为什么wchar_t的发明? [英] Why was wchar_t invented?
问题描述
为什么 wchar_t的
需要的?它是如何优于短
(或 __ INT16
或其他)?
(如果它的事项:我住在Windows世界中,我不知道什么是Linux确实支持UNI到code)
为什么需要的wchar_t?它是如何优于短(或__int16或其他)?
块引用>在C ++的世界,
wchar_t的
是它自己的类型(我认为这是一个的typedef
C语言),所以你可以重载基于此功能。例如,这使得它可以输出宽字符和的不的输出的数值。在VC6,其中wchar_t的
只是一个的typedef
为无符号短
这codewchar_t的WCH = L'A'
的std :: wcout<< WCH;将输出
65
,因为的std :: ostream的<&的wchar_t GT; ::运算<<(无符号短)
被调用。在较新版本的VC
wchar_t的
是一个独特的类型,所以的std :: ostream的<&的wchar_t GT; ::运算<<(wchar_t的)
被调用,并且输出
A
。Why is
wchar_t
needed? How is it superior toshort
(or__int16
or whatever)?(If it matters: I live in Windows world. I don't know what Linux does to support Unicode.)
解决方案Why is wchar_t needed? How is it superior to short (or __int16 or whatever)?
In the C++ world,
wchar_t
is its own type (I think it's atypedef
in C), so you can overload functions based on this. For example, this makes it possible to output wide characters and not to output their numerical value. In VC6, wherewchar_t
was just atypedef
forunsigned short
, this codewchar_t wch = L'A' std::wcout << wch;
would output
65
becausestd::ostream<wchar_t>::operator<<(unsigned short)
was invoked. In newer VC versions
wchar_t
is a distinct type, sostd::ostream<wchar_t>::operator<<(wchar_t)
is called, and that outputs
A
.这篇关于为什么wchar_t的发明?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!