1.如题,VC++6.0默认GB2312编码,项目需要UTF-8,从网上找了一个转换程序,出调用函数结束后总是会多出200字节左右的重复代码(如A+B+C转换之后变为A%..B%..C%..B%..)这种情况
2.猜测原因为UTF-8中英文只占1字节,而某些字符则占2字节,导致长度测定错误
求大佬指导,下文为引用函数:
void ConvertGB2312ToUtf8(char* gb2312,char *out)
{
int len1=MultiByteToWideChar(CP_ACP, 0, gb2312, strlen(gb2312), NULL,0);
unsigned short * wszUtf8 = new unsigned short[len1+1];
memset(wszUtf8, 0, len1);
MultiByteToWideChar(CP_ACP, 0, gb2312, strlen(gb2312), wszUtf8, len1);
int len2 = WideCharToMultiByte(CP_UTF8, 0, wszUtf8, -1, NULL, 0, NULL, FALSE);
char *szUtf8=new char[len2];
memset(szUtf8, 0, len2);
WideCharToMultiByte (CP_UTF8, 0, wszUtf8, -1, szUtf8, len2, NULL,FALSE);
memcpy(out,szUtf8,strlen((char *)szUtf8));
delete[] szUtf8;
delete[] wszUtf8;
}