[英]Why w/cout does not support string U/u prefixes?
I have the following code inspired by one of the SO questions: 我有以下受SO问题之一启发的代码:
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. cout
具有类似的输出。
I understand from the answer on this post that w/cout does not support the string U/u prefixes, or exactly as mentioned: 我从这篇文章的答案中了解到,w / cout不支持字符串U / u前缀,或者不完全如前所述:
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.同时
std::cout's
类对于const char16_t*
,const char32_t*
和const wchar_t*
没有特殊的<<
重载,因此它将匹配<<
的重载以打印指针。
My questions are: 我的问题是:
1- Why it does not support these types? 1-为什么它不支持这些类型? 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?
2-是否有已知的计划在可见的将来增加这种支持?
I know that iostream is a library, but, practically, it is still part of the language. 我知道iostream是一个库,但是实际上,它仍然是该语言的一部分。
The usual answer to standard library omissions applies: nobody proposed to add overloads for char16_t const*
or char32_t
. 对标准库遗漏的通常答案是:没有人建议为
char16_t const*
或char32_t
添加重载。 The proposal to add the character types ( N2249 ) did not contain the relevant library parts. 添加字符类型的建议( N2249 )不包含相关的库部分。 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. 由于这些运算符的重载为
void const*
,因此将打印指针的地址。 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. 由于新字符类型毫无意义(至少,从我的角度来看:仅使用UTF8),我怀疑是否有人对创建建议感兴趣。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.