+ 1
Suppose that there asked user to input char variable. How to make c++ to recognize entered character as int if it is a digit?
C++
4 Respuestas
+ 6
If a user is entering data in the form of a string, then you can use the atoi function to change it to an int.
Format: atoi(const char * str)
+ 1
Based on the ASCII table you can use this condition:
if (c>='0'&&c<='9')
+ 1
Also, if you know beforehand that the input is a number, you can use:
int input;
cin >> input;
+ 1
you you have a chat variable "input" storing entered digit, then to convert it to int you can do this:
int converted = input - '0';