how to check type in c 2b 2b

Solutions on MaxInterview for how to check type in c 2b 2b by the best coders in the world

showing results for - "how to check type in c 2b 2b"
Alena
10 Jan 2020
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}