What I want are a few statements that will clear an input stream of all characters currently in its buffer.
It seems like a super simple and reasonable task, but every solution I've ever gotten is either too complicated to understand, or doesn't work, or both.
I've tried using ignore()
, but then if there's nothing in the input buffer, it waits for me to put something in for it to dispose of, until it's disposed of the exact number of characters I specified. getline()
and cin.peek()
work the same way, waiting for input if there isn't any yet. cin.sync()
works to some degree, but it can't clear out endl
characters; it gets stuck there.
I'd really like to be able to clear out multiple lines if necessary.