c++ - difference between L"" and u8"" -
is there difference between followings?
auto s1 = l"你好"; auto s2 = u8"你好"; are s1 , s2 referring same type?
if no, what's difference , 1 preferred?
they not same type.
s2 utf-8 or narrow string literal. c++11 draft standard section 2.14.5 string literals paragraph 7 says:
a string literal begins
u8, suchu8"asdf", utf-8 string literal , initialized given characters encoded in utf-8.
and paragraph 8 says:
ordinary string literals , utf-8 string literals referred narrow string literals. narrow string literal has type “array of n
const char”, n size of string defined below, , has static storage duration (3.7).
s1 wide string literal can support utf-16 , utf-32. section 2.14.5 string literals paragraph 11 says:
a string literal begins
l, suchl"asdf", wide string literal. wide string literal has type “array of nconst wchar_t”, n size of string defined below; has static storage duration , initialized given characters.
see utf8, utf16, , utf32 discussion on differences , advantages of each.
a quick way determine types use typeid:
std::cout << typeid(s1).name() << std::endl ; std::cout << typeid(s2).name() << std::endl ; on system output:
pkw pkc checking each of these c++filt -t gives me:
wchar_t const* char const*
Comments
Post a Comment