I'm working with some code that uses a global debug logger that is of type std::ofstream*
. I would like to redirect this to std::cout since I'm using the code in realtime, as opposed to a batch method for which it was designed.
Is it possible to redirect the global std::ofstream*
pointer it uses to std::cout
? I know std::ofstream
inherits from std::ios
, which allows one to change the stream buffer using the rdbuf()
method, but unfortunately it appears std::ofstream
redefines the rdbuf()
method, which makes the following code not compile:
gOsTrace = new std::ofstream();
gOsTrace->rdbuf(std::cout.rdbuf());
Is there another way to redirect the gOsTrace
object to point to cout
?
std::ofstream*
Can it not be the more genericstd::ostream*
. Then all you to do is make an assignment to this pointer with the new stream. – Conversationstd::cin
flushesstd::cout
when there's an input operation. – Flaminiusnew
gives a pointer but you then use.
on it – Madeup