更新时间:2022-12-29 20:47:09
如下尝试:
std::string s = u8"Your string";
// #include <codecvt>
std::wstring_convert<std::codecvt<char16_t,char,std::mbstate_t>,char16_t> convert;
std::u16string u16 = convert.from_bytes(s);
std::string u8 = convert.to_bytes(u16);
同时检查此用于UTF到UTF的转换。
Also check this for UTF to UTF conversion.
-
专业化codecvt在
之间转换UTF-16和UTF-8编码方案,以及专业化
codecvt在UTF-32和
UTF-8编码方案之间进行转换。
The specialization codecvt converts between the UTF-16 and UTF-8 encoding schemes, and the specialization codecvt converts between the UTF-32 and UTF-8 encoding schemes.