confused by control flow execution in C++ Primer example

…衆ロ難τιáo~ 提交于 2019-12-06 12:18:09

That's because of this part:

while (std::cin >> val)

In order to terminate reading the input stream, you have to terminate it with an EOF, which is supplied by Ctrl-D.

Think about it: cin skips over whitespace by default and every time you enter a number you separate it with whitespace (a space, a tab or a newline).

How will the program ever terminate the input? The answer is when it reads an EOF character - which, as stated before, is supplied by Ctrl-D.

Alastair Maw

You must press CTRL+D because otherwise the program does not know when your stdin stream has finished. It will otherwise just sit there at while (std::cin >> val forever without terminating.

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