C++ typeid 是否返回字符串类型?

标签 c++

当我们使用 typeid 即 typeid(variable).name() 它是否给出字符串作为输出,因为如果它给出它可能有助于与字符串进行比较。

最佳答案

根据标准,它是一个实现定义的空终止const char*:

18.7.1 Class type_info
....

const char* name() const noexcept;

Returns: An implementation-defined NTBS.

Remarks: The message may be a null-terminated multibyte string (17.5.2.1.4.2), suitable for conversion and display as a wstring (21.3, 22.4.1.4)

由于内容是实现定义的,因此无法以可靠的方式与其他字符串进行比较,除非我们将自己限制在特定的实现上。

关于C++ typeid 是否返回字符串类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34030309/

相关文章:

c++ - 如何实现pop()函数

c++ - 编译时不能包含 Sparkle 框架

c++ - itk 图像梯度的 x 和 y 分量

c++ - 无法运行编译器 'cl'

c++ - 使用固定编码的字符串到字节序列的转换,最好是 UTF-8

python - 如何将 QuTip 添加到 canopy?因为试了很多次,每次都报错。

c++ - 创建指向指针对象的指针的正确方法?

c++ - 视觉 C++ :error C2664: 'GetModuleFileNameW' : cannot convert parameter 2 from 'char [260]' to 'LPWCH'

c++ - C++中的构造函数调用歧义

C++:添加逻辑上正确的 if 语句会使我的程序崩溃