I have a file that looks like this:
a
a
a
a
b
b
c
d
d
d
I'm using fstream and sstream to read it, and what i want to achieve is to read through it counting how many times a single element is repeated, so i can add a node to a BST with the repetition count as its key.
I'm hoping to achieve something like this:
myBST.insert("a", 4);
myBST.insert("b", 2);
myBST.insert("c", 1);
myBST.insert("d", 3);
I've tried creating a while loop with a new sstream where the main loop finds an element, counting how many times the value being read by the new sstream is the same as the original sstream, but it doesn't seem to be working:
if (!datos.is_open())
{
cout << "failed to open";
}
string line;
while (getline(datos, line))
{
stringstream ss(line);
int count = 0;
string line2 = line;
stringstream ss2(line2);
while (line2 == line)
{
stringstream ss2(line2);
count++;
}
}
return 0;
Any help is appreciated :)