2011-10-10 9 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_streambufを検索するには、名前空間を指定するinput、またはgzip_decompressorされていないということです。 試してください:exampleはこれを行わないことを

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

理由は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

関連する問題