Checking for an integer?

How can I check to see if the user has input an integer value? I want to be able to display a message when they type something other than integer values but how could I do that?
If you are using std::cin:

1
2
3
4
5
6
int myint = 0;
if(std::cin >> myint) {
    std::cout << "it's an integer";
} else {
    std::cout << "it's not";
}


If they don't put in an integer, you will need to use .clear() and probably .flush() to be able to use the stream again.
Topic archived. No new replies allowed.