读取 cin 直到 EOF

Read cin till EOF

我正在为 and I noticed that http://ideone.com 编写一个示例,可以让我从 cin 读到 EOF,但 Visual Studio 2015 不会。

例如,给定程序:

string i;

while(cin >> i) cout << i << endl;

我可以给输入:

Lorem Ipsum

http://ideone.com will terminate: http://ideone.com/22uNOr

Visual Studio 2015 将继续等待输入,但是直到我按下 Ctrl + Z and 点击 输入

这是 gcc/Visual 工作室的差异还是 http://ideone.com 正在做的事情?

http://ideone.com 上,您可以在 "input" 选项卡上提供输入。输入到此框中的任何内容都将馈送到 cin 并附加 eof 字符。

例如,如果您这样做:

while (cin.get() != decltype(cin)::traits_type::eof());

在您的本地机器上永远不会回来,直到您按下 Ctrl + z 并按下 Enter 但在 http://ideone.com 上,它总是 return 在解析输入到 "input" 选项卡中的所有内容后。