I get some input from the command line and want to support Unicode.
This is my error:
And this is my example code:
#include <iostream> int main() { char test = '█'; } // Characters wanted: █, ▓, or ▒ How can I make my program support Unicode?
A char is usually only 1 byte, meaning it won't be able to store most Unicode characters. You should look into using wchar_t which is required to be large enough to hold any supported character codepoint. The associated char literal looks as follows: L'█'.
wchar_t ... is required to be large enough to hold any supported character codepoint" - that is not the case on Windows, where wchar_t is only 16 bits, so it can't hold Unicode codepoints > U+FFFF, but it can hold UTF-16 code units, which is why Unicode wchar_t strings on Windows are encoded in UTF-16 (previously UCS-2), whereas other platforms can encode wchar_t strings using UTF-32 instead.A char is usually only 1 byte char is always exactly 1 byte.addressable unit of data storage large enough to hold any member of the basic character set of the execution environment and a char is defined as single-byte character <C> bit representation that fits in a byte. However, the common definition of a byte defines it as containing 8 bits, which is not necessarily equivalent to the definition in the standard.
wchar_tworks just fine for Unicode, as long as you take into account thatwchar_tis different sizes on different platforms (16 bits on Windows, 32 bits on others), so usestd::wstringinstead of a singlewchar_tso you can account for the possibility of needing multiplewchar_ts to encode a single Unicode codepoint, and multiple codepints to encode a single Unicode grapheme.