我正在尝试从Boost Gzip过滤器页面编译示例:
#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);
}
Run Code Online (Sandbox Code Playgroud)
可悲的是,我的g ++返回错误:
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
Run Code Online (Sandbox Code Playgroud)
这个函数有什么问题以及如何修改它以使其工作?非常感谢!
链接到Boost Gzip过滤器:http://www.boost.org/doc/libs/release/libs/iostreams/doc/classes/gzip.html
问题是,你没有指定要在其中查找命名空间filtering_streambuf,input或gzip_decompressor.尝试:
#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);
}
Run Code Online (Sandbox Code Playgroud)
除非另有说明,否则文档中介绍的所有类,函数和模板都在命名空间boost :: iostreams中.通常省略命名空间限定.