|
Boost Users : |
Subject: [Boost-users] [iostreams] State of a filtering stream
From: Nicola (nvitacolonna_at_[hidden])
Date: 2010-03-09 14:02:34
Hi,
I have implemented a filtering stream for decompressing bzipped files,
which looks as shown at the end of the message. I have tried to use it
like this:
bz2istream bzippedfile("myfile.bz2");
while (bzippedfile >> data) {
// process data
}
but the program enters an endless loop. The only way I can test for the
end of file is with:
while (bzippedfile.peek() != EOF) {
bzippedfile >> data;
// process data
}
Isn't the first method supposed to work? Is my class missing something?
Regards
Nicola
class bz2istream :
public boost::iostreams::filtering_stream<boost::iostreams::input>
{
public:
bz2istream(std::string const& path) : ff_(path.c_str(),
std::ios_base::in | std::ios_base::binary)
{
if (ff_.fail())
{
// Here we are not distinguishing failbit from badbit...
setstate(std::ios_base::failbit);
}
else
{
push(boost::iostreams::bzip2_decompressor());
push(ff_);
}
}
private:
std::ifstream ff_;
};
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