3 回答
![?](http://img1.sycdn.imooc.com/5458620000018a2602200220-100-100.jpg)
TA贡献1744条经验 获得超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;}
![?](http://img1.sycdn.imooc.com/545845b40001de9902200220-100-100.jpg)
TA贡献1841条经验 获得超3个赞
中文Unicode Hello World
提纲
Unicode项目设置 将控制台代码页设置为Unicode 查找并使用支持要显示的字符的字体。 使用要显示的语言的区域设置。 使用宽字符输出,即 std::wcout
1项目设置
_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.设置地区
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;}
![?](http://img1.sycdn.imooc.com/54584eff000195a302200220-100-100.jpg)
TA贡献1802条经验 获得超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 关注
- 1501 浏览
添加回答
举报