[Rcpp-devel] Redirecting cout/cerr streams to Rprintf

Renaud Gaujoux renaud at mancala.cbio.uct.ac.za
Mon Oct 21 12:24:55 CEST 2013


Hi,

this is somehow a general C++ question, but it could be of interest to all
Rcpp users (I think).

Still for the purpose of RcppOctave, I would like to redirect cout and cerr
streams that are used by Octave to Rprintf REprintf respectively.
Currently I redirect these streams to 2 temporary stringstreams (via the
std::cout.rdbuf get/set methods ) which buffer the output/errors messages
and print them at the end of the Octave call. The standard streams are
restored on exiting the function (in a class destructor).

However, I would like to do this without buffering, i.e. that messages are
printed as they come through the stream. This should be possible through
the definition of a std::stream child class with some method overload that
output the formatted messages as they are pushed into the stream.

Anybody knows which class and method(s) need to be overloaded, or have
hints on how to achieve this in an -- aesthetic -- way?

Thank you.

Bests,
Renaud
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20131021/aae125ce/attachment-0001.html>


More information about the Rcpp-devel mailing list