代码:

    1. 1.#include<typeinfo>
    2. 2.#include<cxxabi.h>
    3. 3.#include<iostream>
    4. 4.#include<string>
    5. 5.
    6. 6. using namespace std;
    7. 7.
    8. 8.int main()
    9. 9.{
    10. 10. int a;
    11. 11. string realType;
    12. 12. realType=abi::__cxa_demangle(typeid(a).name(), 0, 0, 0);
    13. 13. cout<<realType<<endl;
    14. 14.
    15. 15. return 0;
    16. 16.}

    输出结果:

    1.int
    

    注意事项:
    <typeinfo> 的 typeid() 函数用于获取类型,输出的是编译器的修饰名字,需要用 <cxxabi.h> 的 abi::__cxa_demangle 去掉修饰名字,显示真正的类型