当前位置: 代码迷 >> 综合 >> C/C++线程与多线程工作笔记0005---c/c++中的wchar_t类型
  详细解决方案

C/C++线程与多线程工作笔记0005---c/c++中的wchar_t类型

热度:61   发布时间:2024-02-28 10:33:58.0

技术交流QQ群【JAVA,C++,Python,.NET,BigData,AI】:170933152

#include <iostream>
#include <locale>           //setlocale函数在locale头文件中定义
using namespace std;
int main()
{//使用setlocale函数将本机的语言设置为中文简体//LC_ALL表示设置所有的选项(包括金融货币、小数点,时间日期格式、语言字符串的使用习惯等),chs表示中文简体setlocale(LC_ALL, "chs");wchar_t wt[] = L"中国伟大复兴梦";   //大写字母L告诉编译器为"中"字分配两个字节的空间wcout << wt << endl;               //使用wcout来代替cout输出宽字符return 0;
}

 

标准里面是这样解释的:

Wide character

宽字节字符

Type whose range of values can represent distinct codes for all members of the largest extended character set specified among the supported locales.

In C++, wchar_t is a distinct fundamental type (and thus it is not defined in <cwchar> nor any other header).

在C++中,它是一个特有的基本类型(因此它并没有在<cwchar>或其他header中被定义)

In C, this is a typedef of an integral type.

在C中,这是一个整数类型的typedef


wchar_t 是C/C++的字符类型,一种扩展的存储方式,主要用在国际化程序的实现中。

char是8位字符类型,最多能包含256种字符,许多的外文字符集所包含的字符数目超过256个,char型不能表示。

比如对于汉字,韩文以及日文这样的字符,它们的每一个文字都占据两个字节,所以C++提出了wchar_t类型,也称为双字节类型,或宽字符类型。