These threads do NOT answer me:
resetting a stringstream
How do you clear a stringstream variable?
std::ifstream file( szFIleName_p )
It depends what you're doing with it. It's generally easier to just
create a new istringstream or ostringstream. To "reset" a stream,
you have to clear its buffer, clear any error flags, reset any
formatting flags, plus the precision and fill, reimbue it with the
original locale, and not forget any extended formatting information
generated with a value returned from xalloc. In sum, impossible to
get correct.
And while I'm at it, your loop is wrong, and will probably result in the
last line being processed twice. file.eof() only has a usable meaning
after the input has failed (and even then, it's not 100% reliable).
What you want is:
std::string line;
while ( std::getline( file, line ) ) {
if ( !line.empty() ) {
std::istringstream buffer( line );
// ...
}
}
(Actually, you probably want to trim trailing white space from the line before the test for empty.)