Hey!
I have been sitting with a problem for some time now, and cant figure out how it can be solved. I have some thoughts about it, and am gonna write that down after I posted the code.
Code:
string line;
string word;
std::stringstream strstream;
while(!inout.eof())
{
getline(inout,line);
strstream.clear();
strstream.str(line);
while(!strstream.eof())
{
strstream >> word;
cout << "(" << word << ")";
}
cout << "_ENT_";
}
Lets say my file.txt is:
----
one two three
four five six
seven
------
it will write out:
.......
one two three
three
four five six
six
six
seven
------------
I made a Debug, step by step and went through it and saw where the problem is. It happens when it goes in this loop.
Code:
while(!strstream.eof())
{
strstream >> word;
cout << "(" << word << ")";
}
when it reads the first line "one two three", it goes fine, but the problem appears when it reaches next line. Now when the next line is empty, the strstream dont see it as eof(), and therefor goes in the loop and print the last word "word" got.
I know that the problem happens when it reaches a empty line, and that it doesnt happen if theres a string on that line.
Now my problem is, can I get a tip on how to solve it?