为什么有些C标准库`operator <<`函数将它们的流宽度重置为
发布时间:2020-12-16 07:07:57 所属栏目:百科 来源:网络整理
导读:如C标准的[ostream.inserters.character]部分所述,在将char或字符串插入流后,流的宽度设置为0: templateclass traits basic_ostreamchar,traits operator(basic_ostreamchar,traits out,const unsigned char* s);Do lots of sensible and expected things..
如C标准的[ostream.inserters.character]部分所述,在将char或字符串插入流后,流的宽度设置为0:
template<class traits> basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>& out,const unsigned char* s); Do lots of sensible and expected things... Calls width(0). 为什么C标准规定了对宽度(0)的调用? 更改流宽度而不将其重置为原始值的合理性是什么? 有一个相关的问题here,它表明了这引起的混乱,但没有解释为什么标准规定了这种行为. 解决方法
它似乎不是“某些”运算符<<函数,通常是插入器和提取器(21.4.8.9).见
c++ standard和
Tony D’s answer的明智推理
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |