I'm trying to follow the logic of this question to create a custom streambuf in Rcpp. Someone contributed the basic behaviour that allows us to write things like
Rcout << "some text" ;
where we implemented xsputn and overflow to redirect to Rprintf function. 
std::streamsize Rcpp::Rstreambuf::xsputn(const char *s, std::streamsize num ) {
    Rprintf( "%.*s", num, s );
    return num;
}
int Rcpp::Rstreambuf::overflow(int c ) {
    if (c != EOF) {
        Rprintf( "%.1s", &c );
    }
    return c;
}
I would like to implement flushing too, i.e. support this syntax:
Rcout << "some text" << std::flush ;
Which method do I need to implement so that the flush manipulator works on my custom stream ?
It is sync() function (like in filebuf):
protected:
virtual int sync()
Base version of base_streambuf<>::sync() does nothing, one must overwrite it to make some synchronization with underlying stream.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With