链接c ++流

pio*_*otr 3 c++ iostream

我在考虑"链接"几个c ++ iostream,以便过滤两次输入.我正在使用gzstreams来读取zlib压缩文件,我正在考虑编写从流中读取并执行编码转换的流.也许通过传递一个打开的流作为构造函数参数...你怎么认为这可以做得最好?

Eug*_*ota 6

我没有使用过这个,但是boost的filtering_stream可能有所帮助.

作为一个例子,我发现了一个带有indent.hpp 的邮件列表帖子,它实现了一个缩进输出的输出过滤器:

boost::iostreams::filtering_ostream out; 
indent_filter::push(out,2); 
out.push(std::cout); 
Run Code Online (Sandbox Code Playgroud)

并像这样使用它:

out << "Hello Filter!\n" 
    << indent_in 
    << "this is\n" 
    << "indented\n" 
    << indent_out 
    << "until here\n" 
    ; 
Run Code Online (Sandbox Code Playgroud)

这将导致输出:

Hello Filter! 
  this is 
  indented 
until here 
Run Code Online (Sandbox Code Playgroud)