I have a DLL which uses AllocConsole() to create a new console window.
I would like to use an ostringstream to print out information to this console like so:
1 2
ostringstream s;
s << "This should display within the console" << endl;
I also have file streams which are not meant to be redirected to this window, so how can this be done without interfering?
An ostringstream isn't meant to be directed to the console. It's meant to take in data and turn it into a string. You could do something like this:
1 2
std::ostream& s = /*get output stream*/;
//...
I don't know if std::cout is bound to that when you use AllocConsole()...You might be stuck writing a wrapper class that acts like a stream but uses some Windows stuff internally to write to your AllocConsole()'d output handle.
Okay, so how would you redirect an ostream to a window created using AllocConsole()?
Basically, I don't want to use cout to do this, and don't want any interference with my file streams.