Search code examples
c++unicodewchar-tmojibake

Unexpected output of std::wcout << L"élève"; in Windows Shell


While testing some functions to convert strings between wchar_t and utf8 I met the following weird result with Visual C++ express 2008

std::wcout << L"élève" << std::endl;

prints out "ÚlÞve:" which is obviously not what is expected.

This is obviously a bug. How can that be ? How am I suppose to deal with such "feature" ?


Solution

  • The C++ compiler does not support Unicode in code files. You have to replace those characters with their escaped versions instead.

    Try this:

    std::wcout << L"\x00E9l\x00E8ve" << std::endl;
    

    Also, your console must support Unicode as well.

    UPDATE:

    It's not going to produce the desired output in your console, because the console does not support Unicode.