std::string gb2utf8(const std::string strGBK)
{
const char *str = strGBK.c_str();
const unsigned int CP_GBK = 936;
int len = MultiByteToWideChar(CP_GBK, 0, str, -1, NULL, 0);
wchar_t* buf1 = new wchar_t[len + 1];
memset(buf1, 0, (len + 1)* sizeof(wchar_t));
MultiByteToWideChar(CP_GBK, 0, str, -1, buf1, len);
len = WideCharToMultiByte(CP_UTF8, 0, buf1, -1, NULL, 0, NULL, NULL);
char* buf2 = new char[len + 1];
memset(buf2, 0, len + 1);
WideCharToMultiByte(CP_UTF8, 0, buf1, -1, buf2, len, NULL, NULL);
std::string ret = buf2;
delete[] buf1;
delete[] buf2;
return ret;
}
gbk转换到utf8
最新推荐文章于 2020-12-16 21:20:58 发布