UniCode转UTF8

char *UniCodeToUTF8(CString strUniCode)
{
    LPWSTR pWstr = new wchar_t[strUniCode.GetLength() + 1];
    wcscpy(pWstr, T2W((LPTSTR)strUniCode.GetString()));

    //获取转完后的长度
    int nLen = WideCharToMultiByte(CP_UTF8, 0, pWstr, -1, NULL, NULL, NULL, NULL);
    char *szUtf8 = new char[nLen + 1];
    memset(szUtf8, 0, nLen + 1);

    //转换
    WideCharToMultiByte(CP_UTF8, 0, pWstr, -1, szUtf8, nLen, NULL, NULL);
    delete[] pWstr;
    return szUtf8;
}
posted @ 2018-07-22 14:12  cpluspluser  阅读(290)  评论(0编辑  收藏  举报