Pinned Update #1

The Darc Library (C++) is now updated as of March, 2012. Click ▷here too browse the entire solution.

Friday, August 10, 2012

Wide Characters

Here's how to output wide characters (i.e., wchar_t) to the console in Visual Studio 2010 using a Multi-Byte character set environment. Most likely, this option must be set manually since Microsoft suggest Unicode by default. This setting prevents certain functions from being changed to their <method>W versions but i guess that's a matter of taste. All it takes is a single call to _setmode() with the second parameter indicating the expected character type. In the case of UTF-16 (two bytes) this is _O_U16TEXT. After that, the character type can be switched back to ASCII using the _O_TEXT option.

_setmode(_fileno(stdout), _O_U16TEXT);
std::wcout<<L"Hello World"<<L"\n";  
_setmode(_fileno(stdout), _O_TEXT);  
Wide Character Output

Of course, the console's font must be set to something that can handle all used characters (e.g., Lucida Sans Unicode). The complete Unicode table can be found ▷here.

No comments:

Post a Comment