[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;
}

 

运行结果:

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM