C++ C++;typeid是否返回字符串类型?
当我们使用typeid,即typeid(variable).name()时C++ C++;typeid是否返回字符串类型?,c++,C++,当我们使用typeid,即typeid(variable).name()时 它是否将字符串作为输出,因为如果它这样做,将有助于与字符串进行比较。根据标准,它是一个实现定义的以null结尾的const char*: 18.7.1课程类型信息 const char*name()const noexcept 返回:定义的实现NTB 备注:消息可能是一个以null结尾的多字节字符串(17.5.2.1.4.2),适合转换 并显示为wstring(21.3,22.4.1.4) 由于内容是实现定义的,因此无
它是否将字符串作为输出,因为如果它这样做,将有助于与字符串进行比较。根据标准,它是一个实现定义的以null结尾的
const char*
:
18.7.1课程类型信息const char*name()const noexcept代码>
返回:定义的实现NTB
备注:消息可能是一个以null结尾的多字节字符串(17.5.2.1.4.2),适合转换
并显示为wstring
(21.3,22.4.1.4)
由于内容是实现定义的,因此无法以可靠的方式与其他字符串进行比较,除非我们将自己限制在特定的实现中。尝试此操作时,我得到了Ss
#include <string>
#include <typeinfo>
#include <iostream>
using namespace std;
int main(int argc, char** argv) {
string str = "string";
cout << typeid(str).name();
return 0;
}
#包括
#包括
#包括
使用名称空间std;
int main(int argc,字符**argv){
string str=“string”;
couttypeid(variable).name()
指针是以null结尾的字符串,可以使用strcmp()
进行比较。但是检查变量类型的更好方法是
if (typeid(a) == typeid(int))
即使对于用户定义的数据类型,我们也可以使用这个权利?typeid(a)=typeid(class),其中a是类的对象。