windows - WriteConsoleW, wprintf and Unicode -


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 wprintf stop after printing qwe? \0 byte encountered in ą should terminate wide-char string, afaik

the stdout stream can redirected , therefore operates in 8-bit mode. unicode string pass wprintf() gets converted utf-16 8-bit code page that's selected console. default that's olden 437 oem code page. that's buck stops, code page doesn't support character.

you'll need switch 8-bit code page, 1 support character. choice 65001, code page utf-8. fix:

 setconsoleoutputcp(cp_utf8); 

or use setconsolecp() if want stdin use utf-8 well.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -