// UTF-8 to gb2312 conversion 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); 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 ;} // conversion from gb2312 to UTF-8 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 ;} whether it is gb2312 to UTF-8 conversion, or UTF-8 to gb2312 conversion, You need to note that after using the string, you need to delete the string pointer; this is because the above two methods return a string pointer, if it is not deleted, the memory will leak, not to mention that I didn't remind you.