所以我有一段代码,我想,我需要延迟_getch输入,以便让cout完成。目前,垃圾邮件或按住适当的按钮收集输入的速度比我刷新控制台并以某种方式存储它们的速度更快,所以松开按钮后,需要一些时间才能完成刷新和打印。
我试着清除待定couts,但是我不能这样做。我也尝试过在_getch()之前使用Sleep(),但是直接这么做是行不通的。
编辑
我所能找到并理解的任何刷新或缓冲区清除对我来说也不起作用,因此我试图放慢输入收集的速度。
我也会对一种更快的方式来输出巨大的2D char数组或优化控制台更新感兴趣。
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);
}发布于 2019-12-28 20:16:17
多亏了大家的支持,这件事终于解决了。使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);
}https://stackoverflow.com/questions/59506510
复制相似问题