本文介绍了WriteConsoleW,wprintf和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");

输出为:

qweąęėšų
qwe



b $ b

为什么打印qwe后wprintf停止? \0在ą中遇到的字节应该终止宽字符串,AFAIK

Why does wprintf stop after printing qwe? \0 byte encountered in ą should terminate wide-char string, AFAIK

推荐答案

我接受Hans Passant的答案, wprintf不打印到UTF-8流的根本原因是,wp​​rintf的行为好像使用函数wcrtomb,它将宽字符(wchar_t)编码为多字节序列,具体取决于当前语言环境 - 。
Windows没有支持UTF-8的区域设置(支持UTF-8代码页(65001)的区域设置)。

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)).

这篇关于WriteConsoleW,wprintf和Unicode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 13:11