UTF-8转ANSI的方法

void ConvertUTF8ToANSI(char* strUTF8,CString &strANSI) // { int nLen = ::MultiByteToWideChar(CP_UTF8,MB_ERR_INVALID_CHARS,(LPCTSTR)strUTF8,-1,NULL,0); //返回需要的unicode长度 WCHAR * wszANSI = new WCHAR[nLen+1]; memset(wszANSI, 0, nLen * 2 + 2); nLen = MultiByteToWideChar(CP_UTF8, 0, (LPCTSTR)strUTF8, -1, wszANSI, nLen); //把utf8转成unicode nLen = WideCharToMultiByte(CP_ACP, 0, wszANSI, -1, NULL, 0, NULL, NULL); //得到要的ansi长度 char *szANSI=new char[nLen + 1]; memset(szANSI, 0, nLen + 1); WideCharToMultiByte (CP_ACP, 0, wszANSI, -1, szANSI, nLen, NULL,NULL); //把unicode转成ansi strANSI = szANSI; delete wszANSI; delete szANSI; }

你可能感兴趣的:(VC/MFC)