I'm trying to compile example from Boost Gzip filters page:
#include <fstream>
#include <iostream>
#include <boost/iostreams/filtering_streambuf.hpp>
#include <boost/iostreams/copy.hpp>
#include <boost/iostreams/filter/gzip.hpp>
int main()
{
using namespace std;
ifstream file("hello.gz", ios_base::in | ios_base::binary);
filtering_streambuf<input> in;
in.push(gzip_decompressor());
in.push(file);
boost::iostreams::copy(in, cout);
}
Sadly my g++ returns errors:
gzlib.cpp: In function ‘int main()’:
gzlib.cpp:12:3: error: ‘filtering_streambuf’ was not declared in this scope
gzlib.cpp:12:23: error: ‘input’ was not declared in this scope
gzlib.cpp:12:30: error: ‘in’ was not declared in this scope
gzlib.cpp:13:29: error: ‘gzip_decompressor’ was not declared in this scope
What's wrong with this function and how to modify it to make it work? Thanks a lot!
Link to Boost Gzip filters: http://www.boost.org/doc/libs/release/libs/iostreams/doc/classes/gzip.html
The problem is that you are not specifying the namespace in which to look up filtering_streambuf
, input
, or gzip_decompressor
.
Try:
#include <fstream>
#include <iostream>
#include <boost/iostreams/filtering_streambuf.hpp>
#include <boost/iostreams/copy.hpp>
#include <boost/iostreams/filter/gzip.hpp>
int main()
{
using namespace std;
using namespace boost::iostreams;
ifstream file("hello.gz", ios_base::in | ios_base::binary);
filtering_streambuf<input> in;
in.push(gzip_decompressor());
in.push(file);
copy(in, cout);
}
The reason that the example does not do this is because of the convention established in the introduction:
All classes, functions and templates introduced in the documentation are in the namespace boost::iostreams, unless otherwise indicated. Namespace qualification is usually omitted.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With