WriteConsoleW,wprintf和Unicode [英] WriteConsoleW, wprintf and Unicode

查看:589
本文介绍了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)编码为多字节序列,具体取决于当前语言环境 - link
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)).

MSDN


可用的区域设置名称,语言,国家/地区代码和代码页的集合包括Windows NLS API支持的所有这些,除了需要超过两个字节的代码页字符,例如UTF-7和UTF-8。

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.

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆