//C++动态获取数据类型
//typeid是关键字
#include <iostream>
#include <cstring>
using namespace std;
void main()
{
char a;
cout << typeid(a).name() << endl;
cout << typeid(10).name() << endl;
cout << typeid(10 + 1.2).name() << endl;
cout << typeid("calc").name() << endl; //const char [5]
cout << typeid("冷").name() << endl; //const char [3]
int *px;
int *py;
if (strcmp(typeid(px).name(), typeid(py).name()) == 0)
{
cout << "==";
}
cin.get();
}总结:CPP作为一种强类型语言,可以自动获取类型,关键字是typeid。使用方法是typeid(变量/变量名).name