Boost logo

Boost Users :

Subject: Re: [Boost-users] [iostreams] Inconsistent state of stream
From: Anand Patel (anand.apatel_at_[hidden])
Date: 2010-05-03 02:00:47


Not sure if it is relevant but, boost::iostreams::copy() closes the stream
and calls destructor on it. So my guess is states are reset upon
destruction.
-Anand

On Thu, Apr 29, 2010 at 1:00 PM, Nicola <nvitacolonna_at_[hidden]> wrote:

> Hi,
> can someone tell me if the behaviour of the enclosed example is a bug?
> In my test, the last two assertions fail, but I don't understand why
> (Boost 1.42.0).
>
> Thanks,
> Nicola
>
> #include <boost/iostreams/copy.hpp>
> #include <boost/iostreams/filtering_stream.hpp>
> #include <boost/iostreams/filter/bzip2.hpp>
> #include <cassert>
> #include <fstream>
> #include <sstream>
>
> struct bz2istream :
> public boost::iostreams::filtering_stream<boost::iostreams::input>
> {
> public:
> bz2istream(std::string const& path) :
> pBz2file(path.c_str(), std::ios_base::in | std::ios_base::binary)
> {
> push(boost::iostreams::bzip2_decompressor());
> push(pBz2file);
> }
> private:
> std::ifstream pBz2file;
> };
>
> int main() {
> bz2istream bzippedfile("foo.bz2");
> std::ostringstream os;
> boost::iostreams::copy(bzippedfile, os);
>
> assert(!(bzippedfile.rdstate() & std::ios_base::goodbit)); // Ok
> assert(bzippedfile.rdstate() & std::ios_base::eofbit); // Fails
> assert(!(bzippedfile.good())); // Fails
> }
>
> _______________________________________________
> 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