将文字分配给std :: u16string或std :: u32string

Geo*_*tis 5 c++ c++11

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

std::string s="good";
std::wstring s=L"good";
Run Code Online (Sandbox Code Playgroud)

我该如何分配给

std::u16string s= 
std::u32string s= 
Run Code Online (Sandbox Code Playgroud)

DrY*_*Yap 14

您可以在此处阅读有关C++字符串文字的内容.

特别是对于UTF-16文字,你的前缀是小写的u:

u16string s = u"...";
Run Code Online (Sandbox Code Playgroud)

对于UTF-32文字,您使用大写的U作为前缀:

u32string s = U"...";
Run Code Online (Sandbox Code Playgroud)