30 std::streambuf*
sbOld =
nullptr;
50 const std::string& out_file,
bool also_to_console =
true,
51 bool also_cerr =
true,
bool append_file =
false,
int bufferSize = 1000)
55 std::ios_base::openmode openMode =
57 if (append_file) openMode |= std::ios_base::app;
58 m_of.open(out_file.c_str(), openMode);
64 m_buf.resize(bufferSize);
68 setp(
nullptr,
nullptr);
71 sbOld = std::cout.rdbuf();
72 std::cout.rdbuf(
this);
77 std::cerr.rdbuf(
this);
85 std::cout.rdbuf(
sbOld);
104 if (pbase() == epptr())
121 if (pbase() != pptr())
123 int len = int(pptr() - pbase());
124 std::string temp(pbase(), len);
126 setp(pbase(), epptr());
~CConsoleRedirector() override
std::streambuf * sbOld
The "old" std::cout.
std::vector< char > m_buf
CConsoleRedirector(const std::string &out_file, bool also_to_console=true, bool also_cerr=true, bool append_file=false, int bufferSize=1000)
Constructor.
int overflow(int c) override
mrpt::vision::TStereoCalibResults out
std::ofstream m_of
The text output file stream.
virtual void writeString(const std::string &str)
By creating an object of this class, all the output to std::cout (and std::cerr) will be redirected t...
std::streambuf * sbOld_cerr
The "old" std::cout.
#define THROW_EXCEPTION_FMT(_FORMAT_STRING,...)