问题
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