Printing large characters for narrow streams is not supported and does not work at all. (It "works", but the result is not the one you want).
Printing multibyte narrow lines to wide streams is not supported and does not work at all. (It "works", but the result is not the one you want).
On a Unicode-enabled system, std::cout << "\u2654"
works as expected. So std::cout << u8"\u2654"
. The most correctly configured Unix-based operating systems are ready for use in Unicode.
On a Unicode-enabled system, std::wcout << L'\u2654'
works properly if you correctly configured the localization of your program. This is done with this call:
::setlocale(LC_ALL, "");
or
::std::locale::global(::std::locale(""));
Note "must"; with some compilers / libraries this method may not work at all. This is a flaw in these compilers / libraries. I am looking at you, lib ++. This may or may not be a formal mistake, but I see it as a mistake.
You really need to customize your language in all programs that want to work with Unicode, even if it does not seem necessary.
Mixing cout
and wcout
in one program does not work and is not supported.
std::wcout << U'\u2654'
does not work because it mixes the wchar_t
stream with char32_t
character. wchar_t
and char32_t
are different types. I assume that a properly configured std::basic_stream<char32_t>
will work with char32_t
strings, a bit that the standard library does not provide.
Rows based
char32_t
are good for storing and processing Unicode code points. Do not use them for formatted input and output directly. std :: wstring_convert can be used to convert them back and forth.
TL DRs work with std::stream
and std::string
s, or (if you are not in lib ++) std::wstream
and std::wstring
s.
source share