Comments on my answer here have made me think about how one might implement the same pattern I've been doing with C++ streams. Specifically, I need to be able to have a function which can write to the console, a file, or a string/memory buffer. I don't need most of the formatting features and such that IOStreams provide. Is there some better design which would allow this type of redirection idiomatically that's commonly used in other circles?
for example - for testing I need to be able to write to a string, but for real program use it's always going to be going to a file or the console.