我在考虑将几个C++ iostream链接在一起,使输入经过两次过滤。我正在使用gzstreams来读取zlib压缩文件,并考虑编写一个从流中读取并执行编码转换的流。也许可以通过将已打开的流作为构造函数参数传递来实现...您认为这样做最好的方法是什么?
我没有使用过这个,但是boost的过滤流可能会有所帮助。
举个例子,我找到了一个邮件列表帖子,其中包含indent.hpp,它实现了一个输出过滤器,可以缩进输出:
boost::iostreams::filtering_ostream out;
indent_filter::push(out,2);
out.push(std::cout);
out << "Hello Filter!\n"
<< indent_in
<< "this is\n"
<< "indented\n"
<< indent_out
<< "until here\n"
;
Hello Filter!
this is
indented
until here