zoukankan      html  css  js  c++  java
  • Visual C++ unicode and utf8 转换

    ATL宏:

    USES_CONVERSION;

    W2A

    A2W

    CString StringUtil::UTF8_to_UNICODE(const char *utf8_string, int length)
    {
        int wcsLen = ::MultiByteToWideChar(CP_UTF8, NULL, utf8_string, length, NULL, 0);   
        wchar_t* wszString = new wchar_t[wcsLen + 1];
        ::MultiByteToWideChar(CP_UTF8, NULL, utf8_string, length, wszString, wcsLen);
        wszString[wcsLen] = '';
        CString unicodeText(wszString); 
        delete[] wszString;

        return unicodeText;
    }

    void StringUtil::UNICODE_to_UTF8(const CString& unicodeString, std::string& str)
    {
        int stringLength = ::WideCharToMultiByte(CP_UTF8, NULL, unicodeString, wcslen(unicodeString), NULL, 0, NULL, NULL);

        char* buffer = new char[stringLength + 1];
        ::WideCharToMultiByte(CP_UTF8, NULL, unicodeString, wcslen(unicodeString), buffer, stringLength, NULL, NULL);
        buffer[stringLength] = '';

        str = buffer;

        delete[] buffer;
    }

  • 相关阅读:
    jquey 阻止表单提交
    Array.prototype.remove 删除数组元素
    <asp:HiddenField> 控件 实现键值对保存
    jquery实现倒计时
    作业
    第六周作业
    第四周作业
    第二次作业
    2021.3.4(四个题)
    增删改查
  • 原文地址:https://www.cnblogs.com/lidabo/p/3903616.html
Copyright © 2011-2022 走看看