为什么wchar_t的发明? [英] Why was wchar_t invented?

查看:322
本文介绍了为什么wchar_t的发明?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么 wchar_t的需要的?它是如何优于(或 __ INT16 或其他)?

(如果它的事项:我住在Windows世界中,我不知道什么是Linux确实支持UNI到code)


解决方案

  

为什么需要的wchar_t?它是如何优于短(或__int16或其他)?


在C ++的世界, wchar_t的是它自己的类型(我认为这是一个的typedef C语言),所以你可以重载基于此功能。例如,这使得它可以输出宽字符和的的输出的数值。在VC6,其中 wchar_t的只是一个的typedef 无符号短这code

  wchar_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 to short (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 a typedef 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, where wchar_t was just a typedef for unsigned short, this code

wchar_t wch = L'A'
std::wcout << wch;

would output 65 because

std::ostream<wchar_t>::operator<<(unsigned short)

was invoked. In newer VC versions wchar_t is a distinct type, so

std::ostream<wchar_t>::operator<<(wchar_t)

is called, and that outputs A.

这篇关于为什么wchar_t的发明?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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