_tprintf在控制台应用程序中使用Unicode字符 [英] _tprintf with Unicode characters in a console app
问题描述
我从Unicode编译的控制台应用程序(使用C ++和Visual Studio 2008)做这个简单的输出。此代码旨在在Windows上运行:
I'm doing this simple output from a Unicode-built console application (using C++ and Visual Studio 2008). This code is intended to run on Windows:
_tprintf(L"Some sample string\n");
一切正常。但是如果我在里面添加一个非ASCII字符:
Everything works fine. But if I add an non-ASCII character in there:
_tprintf(L"Some sample € string\n");
输出到控制台是什么东西,直到该字符:
what gets output to the console is everything until that character:
一些示例
Some sample
我在这里做错了什么?
推荐答案
默认情况下,Windows控制台不处理宽字符。启用该功能的最简单的方法是调用 _setmode
:
By default, windows console does not process wide characters. Probably the simplest way to enable that functionality is to call _setmode
:
_setmode(_fileno(stdout), _O_WTEXT);
请参阅 MSDN 了解所需的内容,使用示例和其他可用模式。
See MSDN for the required includes, usage examples, and other available modes.
这篇关于_tprintf在控制台应用程序中使用Unicode字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!