I’ve a program that used to run as a commandline, hence has lots of couts in it. I was wondering if there was a way of creating an ostream object in the class that calls this program and initialize that programs constructor with something like
Import(ostream & text_out= std::cout):out(text_out)
and replace all my calls to cout with out, thereby switching where the output goes.
At the end of each function call, I could then extract the ostream object to a string, and send it to my MFC object.
This would mean my base code would be good if called either as a commandline or an MFC program, if I could get it to work. This could be me thinking along the wrong track, but I’m curious to see if this is possible.
You can use
ostringstream: