isdigit(int c)

Sorry for this, but i am new to c++.
I need to check if input is numeric, and was thinking to control this with the following code.

1
2
3
4
5
6
    int b;
    cin>>b;
    if(isdigit(b))
       cout<<"Is a digit!";
    else
      cout<<"Is not a digit!";


Cane somebody explain why this don't working correct.

Best Regards, Vic
isdigit works with characters. If cin >> b fails, the value of 'b' won't be changed.
see http://www.cplusplus.com/forum/articles/6046/ for input validation
Topic archived. No new replies allowed.