2011-10-10 34 views
5

我试图编译例如从升压Gzip已过滤器页面:升压Gzip已过滤器:编译failes

#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); 
} 

可悲的是我的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 

有什么不对的功能,以及如何修改它使其工作?非常感谢!

链接,以提高Gzip已过滤器:http://www.boost.org/doc/libs/release/libs/iostreams/doc/classes/gzip.html

回答

8

的问题是,你没有指定要在其中查找filtering_streambufinput,或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); 
} 

的原因,example不这样做,这是因为建立在introduction公约:

文档中介绍的所有类,功能和模板是命名空间boost :: iostreams,除非另有说明。命名空间限定通常被忽略。

+0

有很多错误,所以我把输出到pastebin。可能是我的Boost工作不正确? http://pastebin.com/fG2ZqpaJ – ghostmansd

+0

@ghostmansd:如[此处](http://www.boost.org/doc/libs/release/libs/iostreams/doc/classes/gzip.html#installation)所述,你需要链接到'zlib'才能工作。 'zlib'是'boost'外部的,但通常预装在UNIX系统上,否则可以从[here](http://zlib.net/)下载。 – Mankarse

+0

我使用-lz编译,但它没有帮助。 – ghostmansd