获取一个韩语的页面,直接输出韩语显示的是 :口口口口口口
转unicode 韩语显示的都是乱码。转asic显示的都是 ????。
网页中也没有chaset 不知道是什么原因 请教众大大 到底啥原因
转换代码如下
void ConvertUtf8ToGBK(CString& strUtf8)
{
int len=MultiByteToWideChar(CP_UTF8, 0, (LPCTSTR)strUtf8, -1, NULL,0);
unsigned short * wszGBK = new unsigned short[len+1];
memset(wszGBK, 0, len * 2 + 2);
MultiByteToWideChar(CP_UTF8, 0, (LPCTSTR)strUtf8, -1, (LPWSTR)wszGBK, len);
len = WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)wszGBK, -1, NULL, 0, NULL, NULL);
char *szGBK=new char[len + 1];
memset(szGBK, 0, len + 1);
WideCharToMultiByte (CP_ACP, 0, (LPCWSTR)wszGBK, -1, szGBK, len, NULL,NULL);
strUtf8 = szGBK;
delete[] szGBK;
delete[] wszGBK;
}
void Ansi2UTF8(CString &text)
{
DWORD LenUni = MultiByteToWideChar(GetACP(),0,text,-1,NULL,0);
wchar_t *uniStr = new wchar_t[LenUni];
MultiByteToWideChar(CP_ACP,0,text,-1,uniStr,LenUni);
DWORD LenUTF8 = WideCharToMultiByte(CP_UTF8,0,uniStr,-1,NULL,0,NULL,NULL);
char *utf8Str = new char[LenUTF8];
WideCharToMultiByte(CP_UTF8,0,uniStr,-1,utf8Str,LenUTF8,NULL,NULL);
text = (LPCTSTR)utf8Str;
}
------解决思路----------------------
网页应该是UTF-8,你的系统显示不了韩语。
------解决思路----------------------
仅供参考:
#pragma comment(lib,"user32")
#pragma comment(lib,"gdi32")
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
HWND WINAPI GetConsoleWindow();
void HideTheCursor() {
CONSOLE_CURSOR_INFO cciCursor;
HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
if(GetConsoleCursorInfo(hStdOut, &cciCursor)) {
cciCursor.bVisible = FALSE;
SetConsoleCursorInfo(hStdOut, &cciCursor);
}
}
void ShowTheCursor() {
CONSOLE_CURSOR_INFO cciCursor;
HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
if(GetConsoleCursorInfo(hStdOut, &cciCursor)) {
cciCursor.bVisible = TRUE;
SetConsoleCursorInfo(hStdOut, &cciCursor);
}
}
int main() {
HWND hwnd;
HDC hdc;
HFONT hfont;
system("color F0");
system("cls");
HideTheCursor();
hwnd = GetConsoleWindow();
hdc = GetDC(hwnd);
hfont = CreateFont(48, 0, 0, 0, 0, 0, 0, 0, 0 , 0, 0, 0, 0, "Arial Unicode MS");
SelectObject(hdc,hfont);
TextOutW(hdc,10,10,L"你好",2);
DeleteObject(hfont);
hfont = CreateFont(48, 0, 0, 0, 0, 0, 0, 0, JOHAB_CHARSET , 0, 0, 0, 0, "Arial Unicode MS");
SelectObject(hdc,hfont);
TextOutW(hdc,10,80,L"\xb7f0\xb7f0\xb2dd\xb2dd",4);
DeleteObject(hfont);
ReleaseDC(hwnd,hdc);
getch();
system("color 07");
system("cls");
ShowTheCursor();
return 0;
}