|
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-29 00:28:04
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?
Best Regards,
Stephen
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