Newbie asking a question over here

#include <iostream>
#include <limits>

using namespace std;

int main() {
int number = 0;
cout << "Enter an integer: ";
cin >> number;
cin.ignore(numeric_limits<int>::max(), '\n');

if (!cin || cin.gcount() != 1)
cout << "Not a numeric value.";
else
cout << "Your entered number: " << number;
return 0;
}

Can anyone explain the following part to me? :
cin.ignore(numeric_limits<int>::max(), '\n');

if (!cin || cin.gcount() != 1)
cout << "Not a numeric value.";
else
cout << "Your entered number: " << number;



Thanks a lot for the help.
please use the code-tags.

The if-statement tests whethter the reading of the variable number did succeed.
If cin did read something other than an integer, cin will be false. So !cin will become true.
The same for cin.gcount()

int main
The cin.ignore() or the if statement?
For the cin.ignore(), that ignores everything the user puts in up to an endline. Good for pausing, if you can remember what it says.

If block:
Read the above post.
Topic archived. No new replies allowed.