我正在考虑将几个 C++ iostream“链接”在一起以过滤输入两次。我正在使用 gzstreams 读取 zlib 压缩文件,并且正在考虑编码一个从流中读取并执行编码转换的流。也许通过传递一个打开的流作为构造函数参数...您认为这可以最好地实现吗?
我没用过这个但是boost的过滤流 http://www.boost.org/doc/libs/1_38_0/libs/iostreams/doc/classes/filtering_stream.html可能有帮助。
作为一个例子,我发现邮件列表帖子 http://lists.boost.org/Archives/boost/2008/02/133679.php with 缩进.hpp http://lists.boost.org/Archives/boost/att-133679/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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)