我的C ++代码如下所示:
void Typewriter(string strOk) {
for (unsigned int x = 0; x < strOk.length(); x++) {
cout << strOk[x];
Sleep(50);
}
cout << endl;
}
int main() {
Typewriter("OK, Hello. This is a first thingy. IDK.");
Typewriter("This is the second line, also the second call to the function");
cin.get();
Typewriter("You pressed Enter! [Enter] next page");
cin.get();
Typewriter("Haha, no next page. Now, cya!");
return 0;
}
它工作正常,除了cin.get()
等待 Enter 按键时,用户可以输入其他字符,它们将显示在控制台中。。它类似于cin
,但在按下 Enter 时执行下一个语句。如何限制键盘按键显示在控制台中,只有在按下 Enter 时才会作出反应?