3 回答

TA貢獻1744條經(jīng)驗 獲得超4個贊
_setmode(..., _O_U16TEXT)
.
解決辦法:
#include <iostream>#include <io.h>#include <fcntl.h>int wmain(int argc, wchar_t* argv[]){ _setmode(_fileno(stdout), _O_U16TEXT); std::wcout << L"Testing unicode -- English -- Ελληνικ? -- Espa?ol." << std::endl;}

TA貢獻1841條經(jīng)驗 獲得超3個贊
中文Unicode Hello World
提綱
Unicode項目設(shè)置 將控制臺代碼頁設(shè)置為Unicode 查找并使用支持要顯示的字符的字體。 使用要顯示的語言的區(qū)域設(shè)置。 使用寬字符輸出,即 std::wcout
1項目設(shè)置
_UNICODE
UNICODE
int wmain(int argc, wchar_t* argv[])
wmain
main
wmain
2.控制臺代碼頁
chcp
CP_UTF8
SetConsoleOutputCP(CP_UTF8);SetConsoleCP(CP_UTF8);
3.選擇字體
CONSOLE_FONT_INFOEX fontInfo;// ... configure fontInfoSetCurrentConsoleFontEx(hConsole, false, &fontInfo);
4.設(shè)置地區(qū)
char* a = setlocale(LC_ALL, "chinese");
chinese
german
5.使用寬字符輸出
std::wcout << L"你好" << std::endl;
L
UCS-2 LE BOM
.
例
#include <Windows.h>#include <iostream>#include <io.h>#include <fcntl.h>#include <locale.h>#include <wincon.h>int wmain (int argc, wchar_t* argv[]){ SetConsoleTitle(L"My Console Window - 你好"); HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); char* a = setlocale(LC_ALL, "chinese"); SetConsoleOutputCP(CP_UTF8); SetConsoleCP(CP_UTF8); CONSOLE_FONT_INFOEX fontInfo; fontInfo.cbSize = sizeof(fontInfo); fontInfo.FontFamily = 54; fontInfo.FontWeight = 400; fontInfo.nFont = 0; const wchar_t myFont[] = L"KaiTi"; fontInfo.dwFontSize = { 18, 41 }; std::copy(myFont, myFont + (sizeof(myFont) / sizeof(wchar_t)), fontInfo.FaceName); SetCurrentConsoleFontEx(hConsole, false, &fontInfo); std::wcout << L"Hello World!" << std::endl; std::wcout << L"你好!" << std::endl; return 0;}

TA貢獻1802條經(jīng)驗 獲得超4個贊
int _tmain(int argc, _TCHAR* argv[]){ char* locale = setlocale(LC_ALL, "English"); // Get the CRT's current locale. std::locale lollocale(locale); setlocale(LC_ALL, locale); // Restore the CRT. std::wcout.imbue(lollocale); // Now set the std::wcout to have the locale that we got from the CRT. std::wcout << L"?Hola!"; std::cin.get(); return 0;}
- 3 回答
- 0 關(guān)注
- 1534 瀏覽
添加回答
舉報