我正在尝试将 unicode 值(在本例中为 \u250F 或 ┏)插入到控制台输出。我四处搜寻,人们推荐了各种各样的东西。在我们讨论我的尝试之前,我使用的是 Windows 和 Visual Studio 2013。
主要错误
当我尝试多个“修复”时,如果未指定,我总是会得到相同的错误:
Debug Assertion Failed!
Program: ...nts\visual studio 2013\Projects\roguelike\Debug\roguelike.exe
File: f:\dd\vctools\crt\crtw32\stdio\fputc.c
Line: 48
Expression: ((_Stream->_flag & _IOSTRG) || ( fn = _fileno(_Stream),
((_textmode_safe(fn) == _IOINFO_TM_ANSI && !_tm_unicode_safe(fn))))
For more information on how your program can cause an assertion failure,
see the Visual C++ documentation on asserts
(Press Retry to debug the application)
我尝试过的
我尝试执行以下所有操作来输出它:
std::cout << "\u250F";
std::wcout << "\u250F";
std::cout << L"\u250F";
std::wcout << L"\u250F";
std::cout << "┏";
std::wcout << "┏";
std::cout << L"┏";
std::wcout << L"┏";
我如何尝试告诉控制台如何输出 unicode
_setmode(_fileno(stdout), _O_U16TEXT);
看来确实是有问题啊。
system("chcp 65001");
不出错,但不执行任何操作
std::locale::global(std::locale("en_US.utf8"));
它会导致参数“非法”的错误
以下代码对我有用:
我的ENV:vs2013,win7_x64,系统区域设置是“英语(美国)”
SetConsoleOutputCP(CP_UTF8);
_setmode(_fileno(stdout), _O_U8TEXT);
wprintf(L"Interface %s\r\n", pNP->pszwName); //pszwName is a wchar_t*
另一个技巧是你的控制台字体,你的控制台字体是否包含字符“┏”?
google 'cmd font fontlink' 将字体添加到您的 cmd 控制台。
在执行程序之前,在 cmd 控制台中运行“chcp 65001”。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)