Is it possible to flush input stream without '\n'?

I have been searching for like the past half an hour.. am I just being stupid? But I really couldn't find anything to flush the input buffer when the buffer does not contain a '\n'.

How is that possible you ask? _getch().. it's magic.

Why is this necessary you ask? Piano simulator.. without clearing the buffer the stream gets loaded with keys and the piano plays for way too long. Piano playing when the musician isn't playing the keys? Now that's something off a horror story.. and also how my program is working currently.

I could only come up with
while(c = _getch())
Note that I didn't use cin.get() because that would require an enter whereas getch() requires just any key input.

So that works I guess, but I wanted to know if there was some kind of function or something for clearing the input buffer, I mean there's just gotta be something.


First priority is STL implementations and then if that's not possible then let me know other ways of implementing this (let's avoid having to add big dependencies like an entire GUI library, it's just a short console program).

Thanks for reading
Wait.. while(c = _getch()) doesn't work I don't know why I said that..

Umgh would fflush(stdin) technically.. technically work?
Topic archived. No new replies allowed.