当前位置: 代码迷 >> 综合 >> 转 C++11与Unicode及使用标准库进行UTF-8、UTF-16、UCS2、UCS4/UTF-32编码转换 utf8转utf16 utf16转utf8
  详细解决方案

转 C++11与Unicode及使用标准库进行UTF-8、UTF-16、UCS2、UCS4/UTF-32编码转换 utf8转utf16 utf16转utf8

热度:11   发布时间:2023-12-08 23:24:36.0

http://www.cppblog.com/Error/archive/2014/09/25/208413.html


// utf-8
char u8_array[] = u8"破晓的博客";
std::string u8_str = u8"破晓的博客";
// utf-16
char16_t u16_c = u'中';
char16_t u16_array[] = u"破晓的博客";
std::u16string u16_str = u"破晓的博客";
// ucs4
char32_t u32_c = U'破';
char32_t u32_array[] = U"破晓的博客";
std::u32string u32_str = U"破晓的博客";



std::wstring_convert<std::codecvt_utf8<char32_t>, char32_t> utf8_ucs4_cvt;
std::u32string ucs4_cvt_str = utf8_ucs4_cvt.from_bytes(u8_source_str);

  相关解决方案