How do I flush the cin buffer?

c++, cin, io-buffering

Solution

Possibly:

std::cin.ignore(INT_MAX);

This would read in and ignore everything until `EOF`. (you can also supply a second argument which is the character to read until (ex: `'\n'` to ignore a single line).

Also: You probably want to do a: `std::cin.clear();` before this too to reset the stream state.

Problem

How do I clear the cin buffer in C++?

Original source

Related problems