1.

Solve : c++ clearing buffer?

Answer»

is there a SIMPLE way to erase everything in the KEYBOARD BUFFER?
im making a space invaders kinda game, but im using getch() instead of the normal cin. getch() reads in one character from the buffer at a time, but when the ship gets hit by the enemy i have the have the program pause for 3 seconds, during the 3 seconds any keys PRESSED gets processed and i dont want that to happen. cin.ignore messes up the input badly, im not sure why or how it does this but it doesnt work.

my code looks something like this

char m = getch();
if(ship == hit)
flash();

void flash()
{
Sleep(3000);
COUT <<"you died!\n";
cin.ignore(5);
}
anything entered during the Sleep(3000) is processed and causes unwanted movement



Discussion

No Comment Found