Boost logo

Boost Users :

Subject: Re: [Boost-users] [iostreams] How can I use the Stream Insertion operator (<<) with a filtering_streambuf?
From: Stephen Greenfield (StephenG_at_[hidden])
Date: 2013-07-26 02:37:21


Ken --

Much thanks for your response.

I DID try that very syntax -- but in that case NOTHING wound up in the file -- it was empty. I think I also tried to flush the ostream -- but that didn't work.

There seems to be some magic here I am missing -- or maybe it's a problem with the GNU 4.0 G++ compiler/libraries, or an Apple / Mac OS specific implementation issue...

Stephen

On Jul 25, 2013, at 11:10 PM, "Ken Appleby" <ken.appleby_at_[hidden]> wrote:

>> Try:
>
> std::ofstream myFile("hello.z", std::ios_base::out | std::ios_base::binary);
> boost::iostreams::filtering_streambuf<boost::iostreams::output> out;
> out.push(boost::iostreams::zlib_compressor());
> out.push(myFile);
>
> std::ostream os(&out);
> os << "text I want to be compressed and end up in the file..."
>
> On input it would be something like:
>
> std::ifstream myFile( "hello.z", std::ios::in | std::ios::binary );
> boost::iostreams::filtering_streambuf< boost::iostreams::input > in;
> in.push( boost::iostreams::gzip_decompressor() );
> in.push( ifs );
> std::istream is( &in );
> is >> text;
>
>
> Ken Appleby
>
> Soft Optics Ltd


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net