_tprintf with Unicode characters in a console app

末鹿安然 提交于 2019-12-12 10:43:39

问题


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");

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

What am I doing wrong here?


回答1:


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); 

See MSDN for the required includes, usage examples, and other available modes.



来源:https://stackoverflow.com/questions/15443168/tprintf-with-unicode-characters-in-a-console-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!