[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