Catching bad input

int x;

cin >> x;

Is there any way to detect that the user entered an non numeric value. Seems if I feed cin "Hello" it assigns 0 to x; I was expecting to use some sort of try/catch block to detect this type of error.
1
2
3
4
5
6
int x;

if(cin >> x)
{
    // read was successful (user typed an int)
}
Check for !good() and respond appropriately. Don't forget that the user will press the ENTER key after every input.

http://www.cplusplus.com/forum/beginner/18258/#msg92955
http://www.cplusplus.com/forum/beginner/15655/#msg77321
http://www.cplusplus.com/forum/beginner/13044/#msg62827

Good luck!
Thanks that worked.
Topic archived. No new replies allowed.