如何在不使用_setmode的情况下在C ++中输出unicode [英] How to output unicode in C++ without _setmode
问题描述
我试图在控制台输出中插入一个unicode值,在这种情况下为\u250F或┏。我到处搜寻,有人推荐各种各样的东西。在讨论我尝试的操作之前,我正在使用Windows和Visual Studio 2013。
主要错误
当我尝试多个修复时,如果未指定,我总是会遇到相同的错误:
调试断言失败!
程序:... nts\visual studio 2013\项目\roguelike\Debug\roguelike.exe
文件:f:\dd\vctools\crt\crtw32\ \stdio\fputc.c
行:48
表达式:(((_Stream-> _flag& _IOSTRG)||(fn = _fileno(_Stream),
( (_textmode_safe(fn)== _IOINFO_TM_ANSI&&!_ tm_unicode_safe(fn))))
有关程序如何导致断言失败的更多信息,
请参见Visual C ++文档在断言
(按重试以调试应用程序)上
我尝试过的事情
我尝试做以下所有事情来输出它:
< pre class = lang-cpp prettyprint-override>
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,系统区域设置为'English(United States)'
SetConsoleOutputCP(CP_UTF8);
_setmode(_fileno(stdout),_O_U8TEXT);
wprintf(L Interface%s\r\n,pNP-> pszwName); // pszwName是wchar_t *
另一个技巧是您的控制台字体,您的控制台字体是否包含char字符'┏'?
google'cmd font fontlink'将字体添加到您的cmd控制台。
运行'chcp 65001'在执行程序之前,请在您的cmd控制台中。
I'm trying to insert a unicode value, in this case, \u250F, or ┏, to the console output. I have searched around, and people recommending a variety of things. Before we discuss on what I tried, I am using Windows and Visual Studio 2013.
The main error
When I try multiple 'fixes', if not specified, I always get the same error:
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)
What I have tried
I have tried to do all of the following things to output it:
std::cout << "\u250F";
std::wcout << "\u250F";
std::cout << L"\u250F";
std::wcout << L"\u250F";
std::cout << "┏";
std::wcout << "┏";
std::cout << L"┏";
std::wcout << L"┏";
How I tried to tell the console how to output unicode
_setmode(_fileno(stdout), _O_U16TEXT);
Seems to be the problem, really.
system("chcp 65001");
Doesn't error, but doesn't do anything
std::locale::global(std::locale("en_US.utf8"));
It causes an error of where the parameters are "illegal"
Following code works for me: my ENV: vs2013, win7_x64, system locale is 'English (United States)'
SetConsoleOutputCP(CP_UTF8);
_setmode(_fileno(stdout), _O_U8TEXT);
wprintf(L"Interface %s\r\n", pNP->pszwName); //pszwName is a wchar_t*
Another tricks is your console font, does your console font include char character '┏ '?
google 'cmd font fontlink' to add a font to your cmd console.
run 'chcp 65001' in your cmd console before execute your program.
这篇关于如何在不使用_setmode的情况下在C ++中输出unicode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!