2

Possible Duplicate:
How to Output Unicode Strings on the Windows Console

I try to output UTF-16 charachters to console in win32console application, but i cannot change the encoding of output stream, I try to use SetConsoleOutputCP() function but when i use next code for testing

    std::wcout << GetConsoleOutputCP() << std::endl;//output 866
    SetConsoleOutputCP(CP_WINUNICODE);              //if i set CP_UTF8 it works
    std::wcout << GetConsoleOutputCP() << std::endl;//output 866

I get the same result (866) for two cases. When I'm try to set CP_UTF8 it works correct but I need UTF-16, why my attempt is failed and how can I set output stream's encoding to UTF-16?

Community
  • 1
  • 1
abilash
  • 897
  • 3
  • 12
  • 32
  • 1
    You already asked five (!) questions all about problems related to using `wchar_t`, and you keep repeating that you "must use UTF-16". So, *why* do you have to use UTF-16 when you admit that UTF-8 just works? – Yakov Galka Oct 24 '12 at 15:00

1 Answers1

2

You cannot set the encoding to UTF-16 because both, cout and wcout, write to the same byte-oriented stream (STD_OUTPUT_HANDLE) and only byte-oriented encodings are supported. UTF-16 is word oriented. This implies that the only Unicode encoding that can be written to the standard output is UTF-8.

Yakov Galka
  • 70,775
  • 16
  • 139
  • 220