printf 只能提供ANSI/MB 的输出,不支持输出unicode stream.
例如:
wchar_t test[]
=
L
"
测试1234
"
; printf(
"
%s
"
,test);
是不会正确输出的
wprintf 同样不会提供unicode output, 但是他会把wchar_t的string转为locale的SB/MB字符编码,然后输出 例如:
wchar_t test[]
=
L
"
测试Test
"
; wprintf(L
"
%s
"
,test);
会输出??1234之类的字符串,或者不输出任何结果 因为wprintf没有办法把L"测试Test"转为默认的ANSI,需要设置locale
setlocale(LC_ALL,
"
chs
"
); wchar_t test[]
=
L
"
测试Test
"
; wprintf(L
"
%s
"
,test);
会有正确的输出 等同于printf("%ls",test);
综上: CRT I/O functions do not provide Unicode output.