自定义冲洗实现 [英] Custom flush implementation
问题描述
我想要遵循此问题在 streambuf 。 htmlrel =nofollow> Rcpp
。有人贡献了基本的行为,让我们可以写如下
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" ;
其中我们实现了 xsputn
和 overflow
重定向到 Rprintf
函数。
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 ;
我需要实现哪种方法,以便 flush
manipulator是否在我的自定义流上工作?
Which method do I need to implement so that the flush
manipulator works on my custom stream ?
推荐答案
$ c>函数(类似于 filebuf ):
It is sync()
function (like in filebuf):
protected:
virtual int sync()
$ b b
base_streambuf<> :: sync()的基本版本不做任何操作,必须覆盖它以与底层流进行某些同步。
Base version of base_streambuf<>::sync() does nothing, one must overwrite it to make some synchronization with underlying stream.
这篇关于自定义冲洗实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!