Search code examples
c++cinio-buffering

How do I flush the cin buffer?


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


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.