What I want to do
redirect stdout and stderr to one or more files from inside c++
Why I need it
I am using an external, pr
For C++ iostreams, you can use the non-const overload of rdbuf
to set std::cout
to a std::filebuf
. (This is best done by
means of an RAII class, since you have to restore it before
leaving main.) For C FILE*
, you can use freopen
, but
I don't think you'll be able to restore it.
FWIW: both of these solutions use only standard C++ or C, so should be portable.