Here two functions to achieve GB2313 and UTF8 format, mainly for VC + + in the acquisition of Web page content to solve garbled problem, because VC + + default character set is GB2312, the General Chinese web site may return is UTF-8 encoding, so you can use the U2G function to convert.
char* u2g (const char* UTF8) {int len = MultiByteToWideChar (Cp_utf8, 0, UTF8,-1, NULL, 0);
wchar_t* wstr = new Wchar_t[len+1];
memset (wstr, 0, len+1);
MultiByteToWideChar (Cp_utf8, 0, UTF8,-1, WSTR, Len);
Len = WideCharToMultiByte (CP_ACP, 0, Wstr,-1, NULL, 0, NULL, NULL);
char* str = new char[len+1];
memset (str, 0, len+1);
WideCharToMultiByte (CP_ACP, 0, Wstr,-1, str, len, NULL, NULL);
if (WSTR) delete[] wstr;
return str;
//gb2312 to UTF-8 conversion char* g2u (const char* gb2312) {int len = MultiByteToWideChar (CP_ACP, 0, gb2312,-1, NULL, 0);
wchar_t* wstr = new Wchar_t[len+1];
memset (wstr, 0, len+1);
MultiByteToWideChar (CP_ACP, 0, gb2312,-1, WSTR, Len);
Len = WideCharToMultiByte (Cp_utf8, 0, Wstr,-1, NULL, 0, NULL, NULL);
char* str = new char[len+1];
memset (str, 0, len+1);
WideCharToMultiByte (Cp_utf8, 0, Wstr,-1, str, len, NULL, NULL);
if (WSTR) delete[] wstr;
return str; }
C + + gb2312 UTF8 conversion function