#include <typeinfo>
string name = "cpp";
int age = 14;
cout << typeid(age).name() << endl;
cout << typeid(name).name() << endl;
输出:
int
class std::basic_string<char,struct std::char_traits,class std::allocator<
char> >
本文通过C++代码示例展示了如何使用typeid操作符获取变量的类型信息,包括基本类型int和字符串类型的名称。
#include <typeinfo>
string name = "cpp";
int age = 14;
cout << typeid(age).name() << endl;
cout << typeid(name).name() << endl;
输出:
int
class std::basic_string<char,struct std::char_traits,class std::allocator<
char> >
4万+
4672

被折叠的 条评论
为什么被折叠?