How to terminate a program with Ctrl-D?

后端 未结 5 1276
太阳男子
太阳男子 2021-01-20 01:06

I am trying to write a simple program that simulates a calculator. I would like the program to exit or turn-off when the Ctrl+D keystroke is made. I se

5条回答
  •  臣服心动
    2021-01-20 01:37

    If you need to terminate with Ctrl-D while reading input.

     while ( std::cin ) // Ctrl-D will terminate the loop
    {
      ...
    }
    

提交回复
热议问题