Custom flush implementation

霸气de小男生 提交于 2020-01-14 10:07:43

问题


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 ?


回答1:


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.



来源:https://stackoverflow.com/questions/13329812/custom-flush-implementation

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!