Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

_tprintf with Unicode characters in a console app

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?

like image 266
ahmd0 Avatar asked Mar 15 '13 22:03

ahmd0


1 Answers

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.

like image 134
Cubbi Avatar answered Nov 06 '22 19:11

Cubbi