链接c ++流 [英] chaining c++ streams

查看:128
本文介绍了链接c ++流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在想连接两个c ++ iostreams,然后过滤输入两次。我使用gzstreams读取zlib压缩文件,我正在考虑编码一个流从流读取和执行编码转换。

I was thinking of "chaining" a couple of c++ iostreams toghether to filter input twice. I'm using gzstreams to read zlib compressed files and I was thinking of coding a stream that reads from a stream and performs encoding conversions. Perhaps by passing an opened stream as constructor parameter... How do you think this could be best accomplished?

推荐答案

我不知道如何解决这个问题, t使用了此功能,但增强的 filtering_stream 可能有帮助。

I haven't used this but boost's filtering_stream may help.

例如,我发现邮寄名单,其中 indent.hpp ,它实现了缩进输出的输出过滤器:

As an example I found a mailing list post with indent.hpp, which implements an output filter that indents outputs:

boost::iostreams::filtering_ostream out; 
indent_filter::push(out,2); 
out.push(std::cout);




并使用它:

And use it like so:



out << "Hello Filter!\n" 
	<< indent_in 
	<< "this is\n" 
	<< "indented\n" 
	<< indent_out 
	<< "until here\n" 
	;




这将导致输出:

Which will result in output:



Hello Filter! 
  this is 
  indented 
until here

这篇关于链接c ++流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆