Read cin till EOF

﹥>﹥吖頭↗ 提交于 2019-12-13 21:46:37

问题


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

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

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

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


回答1:


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());

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.



来源:https://stackoverflow.com/questions/36648775/read-cin-till-eof

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!