将字面值赋给std::u16string或std::u32string

11

据我所知,可以将字面值分配给一个字符串,例如:

std::string s="good";
std::wstring s=L"good";

如何将值赋给一个变量?

std::u16string s= 
std::u32string s= 

你打算让 x?x"good" 表示什么意思? - Oliver Charlesworth
我只想赋一个字符串值。 - George Kourtis
根据http://www.cplusplus.com/reference/string/u16string/的描述,typedef basic_string<char16_t> u16string; - George Kourtis
1个回答

23
你可以在这里阅读关于 C++ 字符串字面值的信息。here
特别是对于 UTF-16 字面值,你需要在前面加上小写的 u:
u16string s = u"...";

对于 UTF-32 文字,您需要以大写 U 作为前缀:

u32string s = U"...";

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接