Ticket #5908: example.cpp

File example.cpp, 733 bytes (added by Travis Abbott <typedef.struct@…>, 11 years ago)

test case that demonstrates the problem (run ./example sample.txt.gz)

Line 
1#include <boost/iostreams/filter/gzip.hpp>
2#include <boost/iostreams/filtering_stream.hpp>
3
4#include <cstdlib>
5#include <fstream>
6#include <iostream>
7#include <string>
8
9using namespace std;
10using namespace boost::iostreams;
11
12int main(int argc, char** argv) {
13 if (argc != 2) {
14 cerr << "specify a file to decompress.\n";
15 exit(1);
16 }
17
18 ifstream f(argv[1]);
19 if (!f) {
20 cerr << "failed to open " << argv[1] << "\n";
21 exit(1);
22 }
23
24 filtering_stream<input> s;
25 gzip_decompressor gz;
26 s.push(gz);
27 s.push(f);
28 string line;
29 unsigned count = 0;
30 while (getline(s, line) && ++count)
31 cout << line << "\n";
32 cout << "read " << count << " lines\n";
33
34 return 0;
35}