How do I clear the cin buffer in C++?
I have found two solutions to this.
The first, and simplest, is to use std::getline()
for example:
std::getline(std::cin, yourString);
... that will discard the input stream when it gets to a new-line. Read more about this function here.
Another option that directly discards the stream is this...
#include
// Possibly some other code here
cin.clear();
cin.ignore(numeric_limits::max(), '\n');
Good luck!