自己用的 C++ UTF8转GBK 源代
stringUTF8ToGB2132(stringstrSrc){
string result;
WCHAR *wstrSrc = NULL;
char *szRes = NULL;
int i;
// UTF8转换成Unicode
i = MultiByteToWideChar(CP_UTF8, 0, strSrc.c_str(), -1, NULL, 0);
wstrSrc = new WCHAR;
MultiByteToWideChar(CP_UTF8, 0, strSrc.c_str(), -1, wstrSrc, i);
// Unicode转换成GB2312
i = WideCharToMultiByte(CP_ACP, 0, wstrSrc, -1, NULL, 0, NULL, NULL);
szRes = new char;
WideCharToMultiByte(CP_ACP, 0, wstrSrc, -1, szRes, i, NULL, NULL);
result = string(szRes);
if (wstrSrc != NULL)
{
delete[]wstrSrc;
wstrSrc = NULL;
}
if (szRes != NULL)
{
delete[]szRes;
szRes = NULL;
}
return result;
}
喜欢C++ win32的一起交流啊
代码是不是很简单 很清爽, 目前项目再用挺不错的 楼主咋都不发了
页:
[1]