WriteConsoleW, wprintf and Unicode
console, unicode, windows
Solution
At first I accepted Hans Passant answer, but the root cause for wprintf not printing to UTF-8 streams is that wprintf behaves as though it uses the function wcrtomb, which encodes a wide character (wchar_t) into a multibyte sequence, depending on the current locale - link. Windows does not have an UTF-8 capable locale (a locale which would support an UTF-8 codepage (65001)).
Quote from MSDN:
The set of available locale names, languages, country/region codes, and code pages includes all those supported by the Windows NLS API except code pages that require more than two bytes per character, such as UTF-7 and UTF-8.
Problem
``` AllocConsole(); consoleHandle = GetStdHandle(STD_OUTPUT_HANDLE); WriteConsoleW(consoleHandle, L"qweąęėšų\n", 9, NULL, NULL); _wfreopen(L"CONOUT$", L"w", stdout); wprintf(L"qweąęėšų\n"); ``` Output is: ``` qweąęėšų qwe ``` Why does wprintf stop after printing qwe? \0 byte encountered in ą should terminate wide-char string, AFAIK