Capturing a keystroke in C++

后端 未结 4 1862
星月不相逢
星月不相逢 2020-12-18 13:54

I have been doing some reading, and I see that I can use getch() to get a keystroke. What I have seen is that this is considered bad practice, however I have seen conflicti

相关标签:
4条回答
  • 2020-12-18 14:06

    Use getch() if it works. Why not?

    0 讨论(0)
  • 2020-12-18 14:09

    getch() is not a standard function in either C or C++. It's found in some obsolete compilers, such as Turbo C and it's also defined in certain commonly used libraries such as curses, but in any case it's a C function, not C++. For C++ you should probably just stick with standard C++ I/O. If you can't do this for some reason then go for the most portable option, e.g. curses.

    0 讨论(0)
  • 2020-12-18 14:09

    On Windows you can use pdcurses: http://pdcurses.sourceforge.net/, that is compatible with ncurses.

    0 讨论(0)
  • 2020-12-18 14:12

    You want to read from the terminal in non-canonical mode. Use tcsetattr() to turn off the ICANON flag.

    0 讨论(0)
提交回复
热议问题