Consider the following code:
#include <iostream>
using namespace std;
int main()
{
char input;
while (1) {
cout << "Enter: ";
cin.get(input);
cin.ignore(100, '\n'); //requires another `enter`
}
return 0;
}
I want to get the next character in the input buffer, and I want that input buffer to be cleared afterwards. I know that we can use cin.ignore()
to do the cleaning, however, if I used it then I'll have to press enter twice (in case of inputting enter
alone) to enter my input! How can I prevent that from happening?