2011-10-10 37 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