+ 1
Verify input C++
How can I verify what kind of variable was inputted? To verify if it is int, char, double etc.
4 Respuestas
+ 6
You can use the typeid function/operator.
Just include this into your code :
#include <typeinfo>
...
cout << typeid(variable).name();
How it works :
#include <typeinfo>
...
int x = 10;
cout << typeid(x).name();
//outputs 'i'
If you want the system to grant an access once knowing that the variable is a int, etc , you can use that operator alongside with a few 'if-else' statements.
+ 3
I think its because sololearn didnt upload the file required or the function into their online compiler. Afterall its an online compiler, I dont expect it to work as efficient as a offline IDE.
0
For not opening a new question...
Why can't I use cin.get(); function in SoloLearn?
0
Please, give me an example of using typeid along an if statement because I can't compare it with anything...