我有一个涉及流的 C++ 课程的编程作业,我试图更好地理解为什么某些函数会以它们的方式工作。
我正在从带有空格的字符串流中读取文本后的输入。为什么最后一个词在输出中重复?
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;
}
因此,我现在不是在 good 标志上循环,而是将提取作为 while 条件进行:
while (is >> outputstring)
...
这很好用,不会重复最后一句话。这个语句在读完后跳出 while 循环的原因是什么?提取返回对同一流的引用,但它是否检查标志或其他内容?
是否有一个标题可以让您包含所有流?