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
gzli开发者_开发技巧b.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.
精彩评论