标准输入流的问题,兼散分

sam1111 sam1111 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
偶尔看到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上试了,均得到相同的结果,是这两个编译器与标准不符吗?

好久没来了,散分。
...全文
评论 16
收藏 已收藏
分享
返回顶部
sam1111
工具平台和程序库 24,850 成员 27,330 内容