This is probably a simple issue but I can't seem to find an answer or get it to work.
My code has an ostream object that is accumulated by various modules and ultimately displayed to the console. I'd like ALSO to write this ostream object to a file, but do I have to rewrite all of that code using an ofstream object instead, or is there a way to convert one to the other (perhaps via a stringstream?)
For example, many of my existing functions look like
You can call a function that takes osteram& with ostringstream, ofstream, ostrstream, or any other concrete stream type. If I understood your intent correctly, you could use ostringstream, and then display it to console and to the file: