_tprintf with Unicode characters in a console application

I draw this simple conclusion from a Unicode console application (using C ++ and Visual Studio 2008). This code is designed to work on Windows:

_tprintf(L"Some sample string\n"); 

Everything works perfectly. But if I add a non-ASCII character there:

 _tprintf(L"Some sample € string\n"); 

what is displayed on the console is all up to this character:

Example

What am I doing wrong here?

+7
source share
1 answer

By default, the Windows console does not handle wide characters. Probably the easiest way to enable this functionality is to call _setmode :

 _setmode(_fileno(stdout), _O_WTEXT); 

See MSDN for necessary inclusions, usage examples, and other available modes.

+7
source

All Articles