Skip to main content
gamedev.net
🔒 Locked

keyboard buffer in win32 console Program problem

Started by werdy666 Apr 22, 2002 at 2:16 AM 0 replies 250+ views
Original Post
werdy666
werdy666
hi, I have a problem. let me explain. I start the program and a title comes up for around 5 seconds. Then i clear the screen and ask a question and use getline(cin, answer) to get the users guess to my question. This works fine, however, during the title screen i can hit the keyboard and enter etc and when the question comes up it has all the keys i pressed during the title screen and also the enter key which means i have answered the question before i have even read it. How can i clear the keyboard buffer before using the getline command? so that even if u type something on the title screen, it won''t come up in the getline command??? I have tried cin.ignore but this seems to ignore it but i still see the keys i pressed etc. So this is no good. thanks for your help. Werdy 666
werdy666
werdy666
i actually figured it out myself. if anyone else is interested here is what i did.....


do
_getch();
while (_kbhit()!= 0);


seems to clear the keyboard buffer pretty good. I just put that right before my getline in my program.

werdy666

[edited by - werdy666 on April 22, 2002 7:31:59 AM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.