check data type

I'm writing a program to calculate the ballistic range of a projectile but I need a way to check to make sure what the user inputs is a number intead of say, their name. I've heard of typeid and isdigit but I have no idea how to use them, or is there a better way to do this?
The you do cin >> [integer/float and so on]; if there is no number in the stream, failbit will be set. A simple way to check it is if(cin >> [some integer])/*success!*/; else /*fail*/;.
When input fails, to try again, you have to call cin.clear() to reset fail flag, and cin.ignore(numeric_limits<streasize>::max(), '\n'); to clear the stream (note that for numeric_limits you'll have to include <limits>. Also, you could put any number there, but numeric_limits<streamsize>::max will definitely clear everything, while with smaller numbers may have to repeat this operation).
Topic archived. No new replies allowed.