C++11特性--编码转换

    xiaoxiao2022-08-06  7


    某平台价值19860元的编程课程资料免费领取【点我领取】


    #include <codecvt> using namespace std; int main () { string str_gbk = "中文"; string str_utf8; wstring str_utf16; // GBK(GB2312) <-> Unicode wstring_convert<codecvt<wchar_t, char, mbstate_t>> cvt_gbk(new codecvt<wchar_t, char, mbstate_t>("CHS")); str_utf16 = cvt_gbk.from_bytes(str_gbk); str_gbk = cvt_gbk.to_bytes(str_utf16); // UTF-8 <-> Unicode wstring_convert<codecvt_utf8<wchar_t>> cvt_utf8; str_utf8 = cvt_utf8.to_bytes(str_utf16); str_utf16 = cvt_utf8.from_bytes(str_utf8); // GBK(GB2312) <-> UTF8 // 方法:GBK(GB2312) <-> Unicode <-> UTF8 return 0; }
    转载请注明原文地址: https://ju.6miu.com/read-1132106.html
    最新回复(0)