blog
blog copied to clipboard
C++: Check data type
Reference:
- https://stackoverflow.com/questions/11310898/how-do-i-get-the-type-of-a-variable
#include <iostream>
#include <typeinfo>
using namespace std;
int main() {
int an_int = 1;
cout << typeid(an_int).name() << endl; // i
cout << typeid(-2).name() << endl; // i
cout << typeid(3.14).name() << endl; // d
cout << typeid('a').name() << endl; // c
cout << typeid("Hi").name() << endl; // A3_c
cout << typeid("Hello World!").name() << endl; // A13_c
cout << typeid(true).name() << endl; // b
return 0;
}