【发布时间】:2020-08-02 22:00:03
【问题描述】:
(对不起。可能不是最相关的问题......)
根据https://en.cppreference.com/w/cpp/language/string_literal:
""" 宽字符串文字。L"..." 字符串文字的类型是 const wchar_t[N] """
但是,在这种情况下,g++ 似乎选择了 const wchar_t* :
auto sw = L"foo";
cout << "type : " << typeid(sw).name() << " >" << sw << "<\n";
cout << " type : " << typeid( const wchar_t * ).name() << " | type : " << typeid( const wchar_t [] ).name() << "\n";
在 GCC 5.4.0 上给出以下输出:
type : PKw >0x401470<
type : PKw | type : A_w
我做对了吗?
【问题讨论】:
-
提示:使用来自
#include <cxxabi.h>的abi::__cxa_demangle(typeid(T).name(), 0, 0, 0);用g++ 对名称进行分解 -
const wchar_t *和const wchar_t[N]是等价的,因为数组只是指针。 -
@Aplet123 完全错误。
-
@KamilCuk 是的!谢谢!
-
@Geoffroy 谢谢,这个不错!
标签: c++ string-literals widechar