Hello
I've been trying to get boost iostreams filter to work.
Heres the code I managed to write, but theres something I cannot
understand..
It works fine with one small text file and it will process the lines okay,
but when I try to use another text file (which is much bigger) it wont
recognize any line and will return 0 lines counted (though file has around 2
million lines)..
What am I doing wrong? What could be the cause of this?
Best regards
Thanks for help
Heres the code:
#include
#include
#include
#include
#include
#include <fstream>
#include <ostream>
#include <iostream>
#include <string>
using namespace std;
using namespace boost::iostreams;
namespace io = boost::iostreams;
class long_line_counter : public io::line_filter {
public:
explicit long_line_counter(int max_length = 80)
: max_(max_length), count_(0)
{ }
int count() const { return count_; }
private:
std::string do_filter(const std::string& line) {
++count_;
return line;
}
int max_;
int count_;
};
int main() {
filtering_istream fin;
long_line_counter llc(80);
fin.push(boost::ref(llc));
fin.push(file_source("test2.txt", ios::in | ios::binary));
char buf[4012];
while ( fin.read(buf, 4012) && (llc.count() < 7000) ) {
std::cout << "read" << "\n";
}
std::cout << llc.count() << "\n";
return 0;
}