There\'s a ton of information available on overloading operator<< to mimic a toString()-style method that converts a complex object to a string.
operator<<
toString()
As for flags, I don't know if there is any standard somewhere, but it is a good idea to reset them.
Boost has neat raii wrappers for that: IO State Savers