Today I was learning some C++ basics and came to know about wchar_t. I was not able to figure out, why do we actually need this datatype, and how do I use it?
Today I was learning some C++ basics and came to know about wchar_t .
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
wchar_tis intended for representing text in fixed-width, multi-byte encodings; sincewchar_tis usually 2 bytes in size it can be used to represent text in any 2-byte encoding. It can also be used for representing text in variable-width multi-byte encodings of which the most common is UTF-16.On platforms where
wchar_tis 4 bytes in size it can be used to represent any text using UCS-4 (Unicode), but since on most platforms it’s only 2 bytes it can only represent Unicode in a variable-width encoding (usually UTF-16). It’s more common to usecharwith a variable-width encoding e.g. UTF-8 or GB 18030.About the only modern operating system to use
wchar_textensively is Windows; this is because Windows adopted Unicode before it was extended past U+FFFF and so a fixed-width 2-byte encoding (UCS-2) appeared sensible. Now UCS-2 is insufficient to represent the whole of Unicode and so Windows uses UTF-16, still withwchar_t2-byte code units.