I have a programming assignment for a C++ course involving streams and I'm trying to gain a better understanding as to why some of the functions work the way they do.
I am reading input from an istringstream with whitespace after the text. Why does the last word get repeated in the output?
istringstream is;
string inputstring = "The cliched statement regarding the big brown dog and foobar or something ";
string outputstring;
is.str(inputstring);
while (is.good())
{
is >> outputstring;
cout << outputstring << endl;
}
So, instead of looping on the good flag, I am now doing the extraction as the while condition:
while (is >> outputstring)
...
This works well and doesn't repeat the last word. What is it about this statement that breaks out of the while loop when it is done reading? The extraction returns a reference to the same stream, but does it check flags or something?
Is there a single header that allows you to include all the streams?