运用函数
#include <typeinfo>
typeid(a).name() //a为变量名称
代码实测
#include <iostream>
#include <string>
#include <typeinfo>
using namespace std;
int main(){
int num = 0;
char cha = 'a';
float flo = 1.0;
double dbe = 2.3;
bool boo = false;
string str = "haihong";
cout<< "num的类型是 " << typeid(num).name() <<endl;
cout<< "cha的类型是 " << typeid(cha).name() <<endl;
cout<< "flo的类型是 " << typeid(flo).name() <<endl;
cout<< "dbe的类型是 " << typeid(dbe).name() <<endl;
cout<< "boo的类型是 " << typeid(boo).name() <<endl;
cout<< "str的类型是 " << typeid(str).name() <<endl;
}
输出结果