1#include <typeinfo>
2#include <iostream>
3
4class someClass { };
5
6int main(int argc, char* argv[]) {
7 int a;
8 someClass b;
9 std::cout<<"a is of type: "<<typeid(a).name()<<std::endl;
10 // Output 'a is of type int'
11 std::cout<<"b is of type: "<<typeid(b).name()<<std::endl;
12 // Output 'b is of type someClass'
13 return 0;
14 // on the online compiler it comes as 'i' for int and 'c' for char
15}
1 if (typeid(variable) == typeid(std::string)) {
2 std::cout << variable << " is a string" << std::endl;
3 }
4 else {
5 std::cout << variable << " is not a string" << std::endl;
6 }//you can do this for every type