GBK转UTF8 C++实现代码



string GBKToUTF8(const std::string& strGBK, int& nLen)  
{  
string strOutUTF8 = "";  
WCHAR * str1;  
int n = MultiByteToWideChar(CP_ACP, 0, strGBK.c_str(), -1, NULL, 0);  
str1 = new WCHAR[n];  
MultiByteToWideChar(CP_ACP, 0, strGBK.c_str(), -1, str1, n);  


n = WideCharToMultiByte(CP_UTF8, 0, str1, -1, NULL, 0, NULL, NULL);  
char * str2 = new char[n];  
nLen = WideCharToMultiByte(CP_UTF8, 0, str1, -1, str2, n, NULL, NULL);  
strOutUTF8 = str2;  
delete[]str1;  
str1 = NULL;  
delete[]str2;  
str2 = NULL;  
return strOutUTF8;  
}  

版权声明:本文为zhangting1987原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。