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