如何清除代码块中的缓冲区

How to clear the buffer in Code Blocks?

本文关键字:缓冲区 代码 何清除 清除      更新时间:2023-10-16

我正在使用代码块,我需要一种好的、简单的方法来清除缓冲区。我使用来自conio.h库的getch()进行输入。

试试这个未经测试的代码:

// send the data to cout here
...
// clear the console input:
while(_kbhit()) _getch();
// Fetch a single key:
char ch = _getch();

u可以使用fflush(stdin);以清除溪流。