Utf8转换

来源:互联网 发布:戏子家事天下知 出处 编辑:程序博客网 时间:2024/05/21 09:30
    std::wstring str = L"测试一下abd";

    std::wstring_convert<std::codecvt_utf8<wchar_t>> conv;

    std::string narrowStr = conv.to_bytes(str);
    {
        std::ofstream ofs("c:\\test.txt");
        ofs << narrowStr;
    }

    std::wstring wideStr = conv.from_bytes(narrowStr);
    {
        std::locale::global(std::locale("Chinese-simplified"));
        std::wofstream ofs(L"c:\\testW.txt");
        ofs << wideStr;
    }
0 0