/*C++获取对象类型
* 可用typeid(object_name).name()函数,该函数在头文件 <typeinfo> 中
*/
#include <iostream>
#include <typeinfo>
using namespace std;
struct Student {
};
int main()
{
int a1 = 0;
int a2[5] = {0,1,2,3,4};
char b[3] = {'0' };
Student x[6];
double* p1 = NULL;
int* p2 = NULL;
string s;
cout << "name = " << typeid(a1).name() << endl;
cout << "name = " << typeid(a2).name() << endl;
cout << "name = " << typeid(b).name() << endl;
cout << "name = " << typeid(x).name() << endl;
cout << "name = " << typeid(p1).name() << endl;
cout << "name = " << typeid(p2).name() << endl;
cout << "name = " << typeid(s).name() << endl;
}
/*
a1 : i // 表示 a1 是 int 类型
a2 : A5_i // 表示 a2 是 int 型 Array(数组),数组有5个元素
b : A3_c // 表示 b 是 char 型 Array(数组),数组有3个元素
x : 6_7Student // 表示 x 是Student类型数组,类型名字有7个字符 ,数组有6个元素
p1 : Pd //表示p1是double 类型Point(指针)类型
p2 : Pi //表示p2是int类型指针
s : NSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
//这个鬼我也不懂
*/
* 可用typeid(object_name).name()函数,该函数在头文件 <typeinfo> 中
*/
#include <iostream>
#include <typeinfo>
using namespace std;
struct Student {
};
int main()
{
int a1 = 0;
int a2[5] = {0,1,2,3,4};
char b[3] = {'0' };
Student x[6];
double* p1 = NULL;
int* p2 = NULL;
string s;
cout << "name = " << typeid(a1).name() << endl;
cout << "name = " << typeid(a2).name() << endl;
cout << "name = " << typeid(b).name() << endl;
cout << "name = " << typeid(x).name() << endl;
cout << "name = " << typeid(p1).name() << endl;
cout << "name = " << typeid(p2).name() << endl;
cout << "name = " << typeid(s).name() << endl;
}
/*
a1 : i // 表示 a1 是 int 类型
a2 : A5_i // 表示 a2 是 int 型 Array(数组),数组有5个元素
b : A3_c // 表示 b 是 char 型 Array(数组),数组有3个元素
x : 6_7Student // 表示 x 是Student类型数组,类型名字有7个字符 ,数组有6个元素
p1 : Pd //表示p1是double 类型Point(指针)类型
p2 : Pi //表示p2是int类型指针
s : NSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
//这个鬼我也不懂
*/