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
GBK到UTF-8转换
最新推荐文章于 2021-02-15 21:04:58 发布
本文提供了一个将GBK编码字符串转换为UTF-8编码的C++实现方法。通过使用Windows API函数MultiByteToWideChar和WideCharToMultiByte,该函数能够有效地完成编码转换,并返回UTF-8编码格式的标准字符串。
1075

被折叠的 条评论
为什么被折叠?



