I have the following code inspired by one of the SO questions:
int main()
{
wcout << "\n\n 1- Test normal string with wcout \n";
wcout << u8"\n 2- Test (u8) string with wcout \n";
wcout << u"\n 3- Test (u) string with wcout \n";
wcout << U"\n 4- Test (U) string with wcout \n";
wcout << L"\n 5- Test (L) string with wcout \n\n";
}
which results in:
cout
has similar output.
I understand from the answer on this post that w/cout does not support the string U/u prefixes, or exactly as mentioned:
Meanwhile
std::cout's
class has no special<<
overload forconst char16_t*
,const char32_t*
andconst wchar_t*
, hence it will match<<
's overload for printing pointers.
My questions are:
1- Why it does not support these types? Isn't it a strange for a language not to support its own types? 2- Are there any known plans to add such support in the seen future?
I know that iostream is a library, but, practically, it is still part of the language.
The usual answer to standard library omissions applies: nobody proposed to add overloads for char16_t const*
or char32_t
. The proposal to add the character types ( N2249 ) did not contain the relevant library parts. In particular, it didn't add overloads for
template <typename charT, typename Traits>
std::basic_ostream<charT, Traits>& std::operator<< (std::basic_ostream<charT, Traits>&, char16_t const*);
template <typename charT, typename Traits>
std::basic_ostream<charT, Traits>& std::operator<< (std::basic_ostream<charT, Traits>&, char32_t const*);
As there is an overload of these operator taking void const*
the address of the pointer is printed. As the new character types are kind of pointless (at least, from my point of view: just use UTF8) I doubt there is anybody interested in creating a proposal.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.