标准输入流的问题,兼散分
偶尔看到C++ Primer上的一段代码,觉得奇怪,试了一下,果然得不到书上的结果:
#include <iostream>
#include <string>
using namespace std;
int main()
{
string word;
while ( cin >> word )
cout << "word read is: " << word << '\n';
cout << "ok: no more words to read: bye!\n";
return 0;
}
输入:riverrun, past Eve and Adam's
书上的结果:
word read is: riverrun,
word read is: past
word read is: Eve
word read is: and
word read is: Adam's
word read is: ok: no more words to read: bye!
我的结果:
word read is: riverrun,
word read is: pass
word read is: Eve
word read is: and
word read is: Adam's
程序未结束。
我在VC.NET和gcc3.0上试了,均得到相同的结果,是这两个编译器与标准不符吗?
好久没来了,散分。