+ 1

Verify input C++

How can I verify what kind of variable was inputted? To verify if it is int, char, double etc.

23rd Dec 2016, 6:34 AM
Gașpar Nicolae
Gașpar Nicolae - avatar
4 Answers
+ 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.
23rd Dec 2016, 7:15 AM
Wen Qin
Wen Qin - avatar
+ 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.
23rd Dec 2016, 8:07 AM
Wen Qin
Wen Qin - avatar
0
For not opening a new question... Why can't I use cin.get(); function in SoloLearn?
23rd Dec 2016, 8:00 AM
Gașpar Nicolae
Gașpar Nicolae - avatar
0
Please, give me an example of using typeid along an if statement because I can't compare it with anything...
23rd Dec 2016, 8:21 AM
Gașpar Nicolae
Gașpar Nicolae - avatar