Boost logo

Boost Users :

Subject: Re: [Boost-users] [iostreams] How can I use the Stream Insertion operator (<<) with a filtering_streambuf?
From: Larry Evans (cppljevans_at_[hidden])
Date: 2013-07-29 12:10:54


On 07/28/13 23:28, Stephen Greenfield wrote:
> On 7/28/13 8:45 PM, "Larry Evans" <cppljevans_at_[hidden]
> <mailto:cppljevans_at_[hidden]>> wrote:
>
> I thought the filtering_stream would be derived from std::ostream, at
> least according to:
>
> Derived class of std::basic_istream, std::basic_ostream or
> std::basic_iostream, used to perform filtering.
>
> quoted from:
>
> http://www.boost.org/doc/libs/1_54_0/libs/iostreams/doc/classes/filtering_stream.html
>
> Did you not find this so, or do you needs require something more
> specific than std::ostream& to be passed to the other functions you
> mention?
>
>
> Larry --
>
> Thanks! You would've thought that — and you know what? You would be
> CORRECT.
>
> I thought I had tested every possible case — but I think I did that
> BEFORE discovering my error with closing the file before destructing the
> filtering_streambuf/filtering_ostream.
>
> You (and everyone else) were ABSOLUTELY CORRECT. When I changed my code
> from a filtering_streambuf:
>
> ofstream myXMLFile (destPath, std::ios_base::out | std::ios_base::app |
> std::ios_base::binary);
> boost::iostreams::filtering_streambuf<boost::iostreams::output>
> filteringOStream;
> filteringOStream.push(boost::iostreams::zlib_compressor());
> filteringOStream.push(myXMLFile);
> std::ostream myExportedXMLFilteringOStream(&filteringOStream);
> Foo(myExportedXMLFilteringOStream);
>
> TO A filtering_ostream:
>
> ofstream myXMLFile (destPath, std::ios_base::out | std::ios_base::app |
> std::ios_base::binary);
> boost::iostreams::filtering_ostream myExportedXMLFilteringOStream;
> myExportedXMLFilteringOStream.push(boost::iostreams::zlib_compressor());
> myExportedXMLFilteringOStream.push(myXMLFile);
> Foo(myExportedXMLFilteringOStream);
>
> Thank you so much for tying up that loose end! I'm assuming the
> filtering_ostream is of course more efficient than the
> filtering_streambuf scenario?
I don't know, but I guess so.

BTW, I tried modifying Ken's code to use filtering_ostream instead
of filtering_streambuf, and it worked. I also removed the ios_base
flags and it still worked. Then I tried using stringstream instead
of filestream and it no longer worked. Anyone have any clues about
why stringstream doesn't work? The code is attached. With the
attached code and attached Jamfile.v2, and with:

  #define USE_STRINGSTRM

in the code, the KenApplebyStrm.output produced by bjam is
in the next attachment.
In contrast, with:
 //#define USE_STRINGSTRM
int the code, the KenApplebyStrm.output produced by bjam is
in the last attachment.
>
> Best Regards,
>
> Stephen
>
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>







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