Sep 1, 2024
wchar_t)char)wchar_t)char), but with some key differences:
char typically uses 1 byte (8 bits) and can represent 256 characters (0-255).wchar_t can use 2 bytes or 4 bytes depending on the compiler.char and wchar_tchar: 256 possible valueswchar_t: Can represent a much larger set of characters (up to 65,536 if 2 bytes are used)char commonly uses ASCII encoding.wchar_t typically uses Unicode encoding, which supports a vast array of characters from different languages and symbols.wchar_t ch = L'a'; // 'L' prefix indicates wide character
wcout instead of cout for wide character output.#include <iostream>
using namespace std;
int main() {
wchar_t ch = L'a';
wcout << L"Character is: " << ch << endl;
cout << "Size of wchar_t: " << sizeof(ch) << " bytes" << endl;
return 0;
}