cocos2d-x win32 log 中文乱码解决办法

来源:互联网 发布:嘉兴市行知小学蔡老师 编辑:程序博客网 时间:2024/05/19 18:39
// gbk_2_utf8string My_gbk_two_utf8(const string text){    #if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)    wstring tes = [=]()    {        setlocale(LC_ALL, "chs");        const char* _tsur = text.c_str();        size_t _tsize = text.size() + 1;        wchar_t* _tdest = new wchar_t[_tsize];        wmemset(_tdest, 0, _tsize);        mbstowcs(_tdest, _tsur, _tsize);        std::wstring result = _tdest;        delete[] _tdest;        setlocale(LC_ALL, "C");        return result;    }();    int asciSize = WideCharToMultiByte(CP_UTF8, 0, tes.c_str(), tes.size(), NULL, 0, NULL, NULL);    if(asciSize == ERROR_NO_UNICODE_TRANSLATION || asciSize == 0)    {        return string();    }    char* resultString = new char[asciSize];    int conveResult = WideCharToMultiByte(CP_UTF8, 0, tes.c_str(), tes.size(), resultString, asciSize, NULL, NULL);    if(conveResult != asciSize)    {        return string();    }    string buffer = "";    buffer.append(resultString, asciSize);    delete[] resultString;    return buffer;#else     return text;#endif}
0 0
原创粉丝点击