Hello everybody,

I am new to C++ and need some help.

In my little program, I declared a variable as integer
and use cin to capture the input from user. How can I validate the datatype to make sure the input is really an integer and not an alphabet?

BTW, the declaration of the variable as an integer does not prevent the user from typing in an alphabet. I tested that.

//my codes:
#include <isostream.h>
int main()
{
int num;
cout << "Please input a number: ";
cin >> num;
if //num is an integer <-- this is where I need help
//then do something
else
cout << "Invalid input" << endl;
}
//end of codes

FYI, I am using VC++ 6.0 and the program is a simple Win32-console application.

Thank you very much.

nina.