Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

chaining c++ streams

Tags:

c++

iostream

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?

like image 884
piotr Avatar asked May 14 '26 15:05

piotr


1 Answers

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

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 
like image 173
Eugene Yokota Avatar answered May 16 '26 05:05

Eugene Yokota