zeion
- 455
- 1
So, I want to use cin >> to get a user input that must only be int.
How can I check the type of the input?
Thanks.
How can I check the type of the input?
Thanks.
int n;
cout << "Give me an integer: ";
while (!(cin >> n))
{
cout << "Hey dummy, I said give me an integer! Try again: ";
// clears the input stream's status flag
cin.clear();
// skip past the next newline, or 1000 chars,
// whichever comes first
cin.ignore(1000,'\n');
}
cout << "You entered " << n << "." << endl;