Custom output formatting for built-in type

Hi all,
I need to change the output format of certain (built-in) types - e.g., doubles - into a custom format (say a base64 encoded version respecting byte ordering on the network and other stuff like that). Any ideas on how to do that without having to resort to methods like replacing every inserted double into something like "hton_custom(0.1)"?

Thanks in advance.
There are a few things you can do:

0) Don't do this to built-in types. Are they coming from some object? Give the object the ability to spit out properly serialized numbers.

1) use your own output function/formatter class as suggested

2) use your own output stream

3) imbue the standard stream with your own num_put facet.

With a few extra lines (think xalloc), you could even have that custom facet produce the default output unless a custom I/O manipulator is in effect.

Most people go for a class, though.
Last edited on
Thanks for the super-fast reply! I went with the num_put facet and a global locale change, as I have quite some stringstreams which I don't have to touch this way. You really saved me a lot of trouble, thanks.
Topic archived. No new replies allowed.