The Code is as follows:
Myurl = "http://www.csdn.net ";
Cinternetsession session;
Chttpfile * thefile = NULL;
Thefile = (chttpfile *) Session. Openurl (myurl );
Cstring szline;
While (thefile-> readstring (szline ))
Chinese characters in szline are garbled
If the webpage to be obtained is gb2312, it can be normally displayed, but csdn is UTF-8 encoded and Chinese is garbled
<Meta http-equiv = "Content-Type" content = "Tet/html; charset = UTF-8"/>
In this case, you need to convert the utf8 string to gb2312 to display Chinese characters correctly.
The method is as follows:
// Convert the utf8 string to gb2312
Void clangconvert: convertutf8togb2312 (cstring STR, _ bstr_t & BSTR)
{
Int n = multibytetowidechar (cp_utf8, 0, STR, str. getlength (), null, 0 );
Wchar * pchar = new wchar [n + 1];
N = multibytetowidechar (cp_utf8, 0, STR, str. getlength (), pchar, N );
Pchar [N] = 0;
Olechar * ptempbuffer = pchar;
BSTR strpassword = sysallocstring (ptempbuffer );
_ Bstr_t AA (strpassword, false );
BSTR = AA;
Sysfreestring (strpassword );
Delete [] pchar;
}