How to read until ESC button is pressed from cin in C++

前端 未结 5 1230
予麋鹿
予麋鹿 2020-12-10 19:17

I\'m coding a program that reads data directly from user input and was wondering how could I read all data until ESC button on keyboard is pressed. I found only something li

5条回答
  •  不思量自难忘°
    2020-12-10 19:59

    I would suggest that for not just ESC character in C++, but for any other character of the keyboard in any language, read characters that you input into an integer variable and then print them as integer.

    Either that or search online for a list of the ASCII characters.

    This will give you ASCII value of the key, and then it's plain simple

    if(foo==ASCIIval)
       break;
    

    For the ESC character, the ASCII value is 27.

提交回复
热议问题