For a C++ console application compiled with Visual Studio 2008 on English Windows (XP,Vista or 7). Is it possible to print out to the console and correctly display UTF-8 encoded Japanese using cout or wcout?
This should work:
#include <cstdio> #include <windows.h> #pragma execution_character_set( "utf-8" ) int main() { SetConsoleOutputCP( 65001 ); printf( "Testing unicode -- English -- Ελληνικά -- Español -- Русский. aäbcdefghijklmnoöpqrsßtuüvwxyz\n" ); }
Don't know if it affects anything, but source file is saved as Unicode (UTF-8 with signature) - Codepage 65001 at FILE -> Advanced Save Options ....
Project -> Properties -> Configuration Properties -> General -> Character Set is set to Use Unicode Character Set.
Some say you need to change console font to Lucida Console, but on my side it is displayed with both Consolas and Lucida Console.
The Windows console uses the OEM code page by default to display output.
To change the code page to Unicode enter chcp 65001
in the console, or try to change the code page programmatically with SetConsoleOutputCP
.
Note that you probably have to change the font of the console to one that has glyphs in the unicode range.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With