5

我正在尝试按照这个问题的逻辑streambufRcpp. 有人贡献了基本的行为,让我们可以写出类似的东西

Rcout << "some text" ;

我们在哪里实现xsputnoverflow重定向到Rprintf功能。

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;
}

我也想实现刷新,即支持这种语法:

Rcout << "some text" << std::flush ;

我需要实现哪种方法才能使flush操纵器​​在我的自定义流上工作?

4

1 回答 1

6

它是sync()函数(如在filebuf中):

protected:
virtual int sync()

base_streambuf<>::sync()的基本版本什么都不做,必须覆盖它才能与底层流进行一些同步。

于 2012-11-11T09:44:06.213 回答