我正在考虑将几个 c++ iostream“链接”在一起以过滤输入两次。我正在使用 gzstreams 读取 zlib 压缩文件,我正在考虑编写一个从流中读取并执行编码转换的流。也许通过将打开的流作为构造函数参数传递...您认为如何最好地实现这一点?
最佳答案
我没用过这个但是 boost 的 filtering_stream可能有帮助。
例如,我找到了 a mailing list post与 indent.hpp ,它实现了一个缩进输出的输出过滤器:
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++ - 链接 C++ 流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/818947/