c ++从<<重载获取流修饰符

jav*_*974 3 c++ overloading stream

我像这样重载了流插入运算符:

template<class Ch, class Tr, class word_type>
std::basic_ostream<Ch, Tr>&
operator << (std::basic_ostream<Ch, Tr>& s, const Mabit::mabit<word_type>& obj)
{
  s << obj.to_string(Mabit::DEC, ',');
  return s;
}
Run Code Online (Sandbox Code Playgroud)

(mabit是我希望重载工作的类)

也就是说,因为我可以在给不同的参数to_string的方法,我想能够使用标准的流修改一样std::dec,std::hex......在某种程度上,我可以取回他们重载运营商准备好参数作为参数to_string

如果我也可以使用该语言环境(为数千个提取分隔符),那么第二个参数也会有所帮助......

那可能吗 ?

Ste*_*all 5

您可以使用它std::basic_ostream::flags()来识别是否使用了格式说明符.

http://en.cppreference.com/w/cpp/io/ios_base/flags