Equivalent to Windows getch() for Mac/Linux crashes

后端 未结 4 1833
心在旅途
心在旅途 2020-12-03 15:27

I am using getch() and my app crashes instantly. Including when doing:

int main()
{
    getch();
}

I can\'t find the link but

4条回答
  •  再見小時候
    2020-12-03 15:45

    Use the cin.get() function for example:

    #include 
    
    using namespace std;
    
    int main()
    {
      char input = cin.get();
    
      cout << "You Pressed: " << input;
    }
    

    The program would then wait for you to press a key.

    Once you have, the key you pressed would be printed to the screen.

提交回复
热议问题