Agoston Bejo wrote:
how can one redirect std::cerr into a file?
I have answered this question loads of times in the past: you can
replace 'std::cerr's stream buffer. However, since 'std::cerr' is
possibly accessed after exiting 'main()', you probably need to
restore the original stream buffer or allocate your stream buffer
on the heap.
Specifically, if I have an ofstream object, is there something I can do to make "cerr << ..."
calls write into that particular ofstream object?
| std::ofstream out(...);
| std::streambuf orig = std::cerr.rdbuf(out.rdbuf());
| ... // use redirected cerr
| std::cerr.rdbuf(orig);
--
<mailto:di***********@yahoo.com> <http://www.dietmar-kuehl.de/>
<http://www.contendix.com> - Software Development & Consulting