我试图遵循以下逻辑这个问题 https://stackoverflow.com/questions/243696/correctly-over-loading-a-stringbuf-to-replace-cout-in-a-matlab-mex-file创建自定义streambuf
in Rcpp http://dirk.eddelbuettel.com/code/rcpp.html。有人贡献了基本行为,使我们能够编写类似的内容
Rcout << "some text" ;
我们在哪里实施xsputn
and overflow
重定向到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
操纵器适用于我的自定义流?
It is sync()
函数(如filebuf http://en.cppreference.com/w/cpp/io/basic_filebuf/sync):
protected:
virtual int sync()
基础版本basic_streambuf::sync() http://en.cppreference.com/w/cpp/io/basic_streambuf/pubsync什么都不做,必须覆盖它才能与底层流进行某种同步。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)