[C++] wchar_t关键字使用方法

char 是单字符类型,长度为一个字节

wchar_t 是宽字符类型,长度为两个字节,主要用在国际 Unicode 编码中

 

举例:

#include<iostream>

using namespace std;

int main(void)
{
    char a = 'A';
    wchar_t b = L'B';
    wchar_t c = L'';

    cout << a << " -> " << sizeof(a) << endl;

    // 宽字符输出用wcout
    wcout << b << " -> " << sizeof(b) << endl;

    // C++中默认为EN_US,中文需转换
    wcout.imbue(locale("chs"));
    wcout << c << " -> " << sizeof(c) << endl;

    return 0;
}

 

运行结果:

 

posted @ 2019-12-08 13:33  LeeAaron  阅读(5533)  评论(1编辑  收藏  举报