I have overloaded the stream insertion operator like this :
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;
}
(mabit being the class for which i wanted the overload to work)
That is, since i can give different argument to the to_string method, i would like to be able to use standard stream modifier like std::dec, std::hex ... in a way that i could retrieve them from the overloaded operator to prepare the good argument as parameter for to_string
If i could also get the locale being used (to extract the separator for thousands) , it would be helpfull for the second argument too...
Is that possible ?
You can use std::basic_ostream::flags() to identify whether an format specifier was used.
http://en.cppreference.com/w/cpp/io/ios_base/flags
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With