smink smink - 5 months ago 40
C++ Question

Is it possible to print a variable's type in standard C++?

For example:

int a = 12;
cout << typeof(a) << endl;

Expected output:




#include <typeinfo>

// …
std::cout << typeid(a).name() << '\n';

You might have to activate RTTI in your compiler options for this to work. Additionally, the output of this depends on the compiler. It might be a raw type name or a name mangling symbol or anything in between.