0

How do I clear a string stream. I am tokenizing a file line by line, and the stringstream is global. I can tokenize the first line, but I can't get the second line working

stringstream currentLine;

while (!inputFile.eof())
{
currentLine << getlinefromfile(); //Gets the next Line
tokenizeLine(); //Tokenizes the line using the global stringstream peek() fnc
currentLine.str("");
currentLine.clear();
}

The above is my current attempt, but it doesnt work.

Trent C
  • 33
  • 3
  • 1
    [`while (!eof())` is wrong.](http://stackoverflow.com/questions/5605125/why-is-iostreameof-inside-a-loop-condition-considered-wrong) – chris Dec 24 '13 at 19:21
  • Possibly related: http://stackoverflow.com/questions/5288036/how-to-clear-ostringstream Declare `currentLine` variable in the loop. – Alex F Dec 24 '13 at 19:25
  • None of these methods work for me. I have tried them to no avail. – Trent C Dec 24 '13 at 19:54
  • I don't see anything wrong with your code. Have you tried instantiating the stringstream inside the loop to see if the error lies elsewhere? You'd then have to pass it to tokenizeLine as an argument, of course. – RJinman Dec 24 '13 at 21:21
  • What do you mean by it doesn't work?? *What* doesn't work? – 0x499602D2 Dec 24 '13 at 23:04

0 Answers0