[iostreams] State of a filtering stream
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_streamboost::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_; };
participants (1)
-
Nicola