所以我有这段代码,我认为我需要延迟_getch输入以腾出时间完成cout。当前,发送垃圾邮件或按住适当的按钮来收集输入内容的速度比我刷新控制台并以某种方式存储它们的速度快,因此,放开按钮后,需要一段时间才能完成刷新和打印。
我已经尝试清除待处理的线索,但是我无法做到这一点。我也尝试过将Sleep()放在_getch()之前,但不能直接使用。
我可以找到并理解的任何刷新或缓冲区清除对我也不起作用,因此我试图减慢输入收集的速度。
我也希望以更快的方式输出巨大的2D字符数组或优化控制台更新。
while (inp != 27)
{
if (inp == 72) cordx -= 1; //up
if (inp == 80) cordx += 1; //down
if (inp == 75) cordy -= 1; //left
if (inp == 77) cordy += 1; //right
//cout of a huge char array, repeated every input
inp = _getch();
coordScreen = { 100, 0 };
SetConsoleCursorPosition(hConsole, coordScreen);
}
感谢大家的支持,已经弄清楚了。使cout依赖_kbhit()
可以解决所有问题。下面更新了代码:
if (inp == 72/* && TAB[cordx - 1][cordy] == true*/) cordx -= 1; //up
if (inp == 80/* && TAB[cordx + 1][cordy] == true*/) cordx += 1; //down
if (inp == 75/* && TAB[cordx][cordy - 1] == true*/) cordy -= 1; //left
if (inp == 77/* && TAB[cordx][cordy + 1] == true*/) cordy += 1; //right
if (_kbhit()==0)
{
//cout of a huge char array, repeated every input
}
inp = _getch();
coordScreen = { 100, 0 };
SetConsoleCursorPosition(hConsole, coordScreen);
}