I would like to know how to test if a char is a number. An int has been converted to char and later on I want to see if this char is a number.
int num = 2;
char number = '2';
char num2 = (char)num;
cout << "Non comverted: " << number << " " << num2 << endl;
cout << "comverted: " << static_cast<int>(number) << " " << static_cast<int>(num2) << endl;
if (isdigit(number))
cout << "number" << endl;
else if (isdigit(num2))
cout << "num2" << endl;
else cout << "none" << endl;
when I run this the second if should also be able to relate to true.
The reason why I want to be able to do this is because I store a lot of different values into a char array and would later like to know when something is a number or not.
Thanx a lot