Boost Gzip 过滤器:编译失败

发布于 2024-12-09 06:41:26 字数 1087 浏览 0 评论 0原文

我正在尝试从 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);
}

遗憾的是我的 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

这个函数有什么问题以及如何修改它以使其工作?多谢!

Boost Gzip 过滤器链接: http://www.boost.org/ doc/libs/release/libs/iostreams/doc/classes/gzip.html

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
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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

放我走吧 2024-12-16 06:41:26

问题是您没有指定要在其中查找 filtering_streambufinputgzip_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);
}

示例 不这样做的原因这是因为简介中建立的约定:

除非另有说明,文档中引入的所有类、函数和模板都位于命名空间 boost::iostreams 中。命名空间限定通常被省略。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文