C++中是否有标准的getch()等价物

Is there a standard getch() equivalent in C++?

本文关键字:getch 等价物 标准 是否 C++      更新时间:2023-10-16

我知道getch不是一个标准的C/C++函数,但我喜欢它,因为它不需要在返回之前按enter键。所以我想知道在标准C++中是否有类似的东西具有相同的效果(不需要按enter键)?

我在这个网站上读到过类似的问题,但他们的回答都没有说明是否有标准的便携式等价物。

如果您使用其中一个"curses"库,例如ncurses

,则有一个可移植的ish等价物

使用ncurses。这是最好也是最简单的选择。

示例代码:

#include <ncurses.h>
 int main()
 {  
   initscr();                   /* Start curses mode          */
   printw("Hello World !!!");   /* Print Hello World          */
   refresh();                   /* Print it on to the real screen */
   getch();                     /* Wait for user input */
   endwin();                    /* End curses mode        */
   return 0;
 }