首页 > 其他 > 详细

Unicode与ANSI的转换

时间:2017-06-30 20:46:27      阅读:285      评论:0      收藏:0      [点我收藏+]
string UnicodeToANSI(const wstring& str)
{
    char *pStr;
    int iwstrLen = WideCharToMultiByte(CP_ACP, 0, str.c_str(), -1, 0, 0, 0, 0);
    cout << "iwstrlen=" << iwstrLen << endl;
    pStr = new char[iwstrLen +1];
    memset(pStr, 0, sizeof(char)*(iwstrLen + 1));
    WideCharToMultiByte(CP_ACP, 0, str.c_str(), -1, pStr, iwstrLen, 0, 0);
    string strText;
    strText = pStr;
    delete pStr;
    cout << "转换ANSI完成" << endl;
    return strText;
}

wstring ANSItoUnicode(const string& str)
{
    WCHAR *pwstr;
    int istrLen = MultiByteToWideChar(CP_ACP, 0, str.c_str(), -1, 0, 0);
    cout << "istrlen=" << istrLen << endl;
    pwstr = new WCHAR[istrLen + 1];
    memset(pwstr, 0, (istrLen + 1) * sizeof(WCHAR));
    MultiByteToWideChar(CP_ACP, 0, str.c_str(), -1, pwstr, istrLen);
    wstring wTemp = pwstr;
    delete pwstr;
    cout << "转换Unicode完成" << endl;
    return wTemp;
}

 

Unicode与ANSI的转换

原文:http://www.cnblogs.com/chaguang/p/7100515.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!