Clearing keyboard buffer in C++
<p>I one part of my application I have used <code>Sleep(5000)</code> (I need to wait 5 sec)</p>

<p>The problem is that if the user presses any keyboard key during these 5 seconds, the keys will be read after sleep and it causes problems for my app.</p>

<p>How can I empty the buffer after sleep?</p>

<p>I tried <code>cin.clear()</code> and <code>setbuf(stdin, NULL)</code> but they can't clear the buffer if there is more than one character in the buffer.</p>
