读cin直到EOF [英] Read cin till EOF

查看:166
本文介绍了读cin直到EOF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为此答案开发一个示例,并且我注意到 http://ideone.com 会让我阅读直到 EOF cin 但Visual Studio 2015不会。

I was working on an example for this answer and I noticed that http://ideone.com will let me read till EOF from cin but Visual Studio 2015 will not.

例如,给定程序:

For example, given the program:

string i;

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

我可以输入:

I can give the input:


Lorem Ipsum

Lorem Ipsum

http://ideone.com 将终止: http://ideone.com/22uNOr

然而,Visual Studio 2015将继续等待输入,直到按 Ctrl + Z 命中 Enter

Visual Studio 2015 will continue waiting for input however until I press Ctrl + Z and hit Enter

这是gcc / Visual Studio的区别还是只是 http://ideone.com 正在做什么?

Is this a gcc/Visual Studio difference or just something http://ideone.com is doing?

推荐答案

您可以在输入选项卡上提供输入。任何输入到这个盒子里的东西都会被送到 cin 后面加上 eof 字符。

On http://ideone.com you can provide input on the "input" tab. Anything inputted into this box will be fed to cin appended with an eof character.

例如,如果你这样做:

For example if you do:

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

在您的本地机器上,只要按 Ctrl + z ,然后按 Enter 但在 http://ideone.com 上它将在解析输入到输入选项卡中的所有内容后始终返回。

On your local machine that will never come back till you press Ctrl + z and press Enter But on http://ideone.com it will always return after parsing everything typed into the "input" tab.

这篇关于读cin直到EOF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆