我想使用箭头键用户输入,而用户每次单击箭头后都不必按 Enter。因此,我决定使用 _getch(),据称它正是这样做的。它是我导入的 conio.h 库的一部分。但是,在我的情况下,_getch() 还要求用户按 Enter 键,并且不会立即注册用户输入,因为它应该这样做。我该如何解决?(我在 Windows 上运行)
#include<iostream>
#include <conio.h>
using namespace std;
int main() {
int p = _getch();
cout<<p;
return 0;
}
例如,在上面的代码中,并没有在控制台接收到输入后直接打印 p 的值,而是等待回车被按下。