我对它做了一些修改。效果很好。我正在运行OSX,所以如果您运行的是Microsoft,那么您需要找到正确的system()命令才能切换到原始模式和熟模式。#include <iostream> #include <stdio.h> using namespace std; int main() {
// Output prompt
cout << "Press any key to continue..." << endl;
// Set terminal to raw mode
system("stty raw");
// Wait for single character
char input = getchar();
// Echo input:
cout << "--" << input << "--";
// Reset terminal to normal "cooked" mode
system("stty cooked");
// And we're out of here
return 0; }