c++utf-8和ansi的互轉



CString MyUTF8toANSI(CString instr) //utf-8-->ansi
{
WCHAR wcharstr[MAX_STRSIZE];
memset(wcharstr,0,MAX_STRSIZE);
MultiByteToWideChar(CP_UTF8,0,(LPCSTR)instr,-1,wcharstr,MAX_STRSIZE);
char charstr[MAX_STRSIZE];
memset(charstr,0,MAX_STRSIZE);
WideCharToMultiByte(CP_ACP,0,wcharstr,-1,charstr,MAX_STRSIZE,NULL,NULL);
CString charstrtemp(charstr);
return charstrtemp;
}

CString MyANSItoUTF8(CString instr) //ansi-->utf-8
{
WCHAR wcharstr[MAX_STRSIZE];
memset(wcharstr,0,MAX_STRSIZE);
MultiByteToWideChar(CP_ACP,0,(LPCSTR)instr,-1,wcharstr,MAX_STRSIZE);
char charstr[MAX_STRSIZE];
memset(charstr,0,MAX_STRSIZE);
WideCharToMultiByte(CP_UTF8,0,wcharstr,-1,charstr,MAX_STRSIZE,NULL,NULL);
CString charstrtemp(charstr);
return charstrtemp;
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM