提升zlib问题

发布于 2024-10-25 02:42:37 字数 1658 浏览 2 评论 0原文

我在 VS 2010 下的 boost 中遇到 zlib 库的问题。我构建了库,并在 boost/stage/lib 文件夹中生成了适当的 dll/libs。我将 .dll 添加到程序调试文件夹中,并链接到匹配的.lib 中。

但是当我实际尝试使用 zlib 流时遇到了问题。这是一个例子:

#include <cstring>
#include <string>
#include <iostream>
#include <boost\iostreams\filter\gzip.hpp>
#include <boost\iostreams\filtering_streambuf.hpp>
#include <boost\iostreams\copy.hpp>
std::string DecompressString(const std::string &compressedString)
{
    boost::iostreams::filtering_streambuf<boost::iostreams::input> in;
    in.push(boost::iostreams::zlib_decompressor());
    in.push(compressedString);
    std::string retString = "";

    copy(in, retString);
    return retString;
}



when I try to compile thise though, I get multiple errors including:
error C2039: 'char_type' : is not a member of 'std::basic_string<_Elem,_Traits,_Ax>'    c:\program files (x86)\boost\boost_1_46_0\boost\iostreams\traits.hpp
error C2208: 'boost::type' : no members defined using this type c:\program files (x86)\boost\boost_1_46_0\boost\iostreams\traits.hpp
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int   c:\program files (x86)\boost\boost_1_46_0\boost\iostreams\traits.hpp

如果我将代码更改为以下内容:

std::string DecompressString(const std::string &compressedString)
{

    boost::iostreams::filtering_streambuf<boost::iostreams::input> in;
    in.push(boost::iostreams::zlib_decompressor());
    std::string retString = "";
    return retString;

}

它可以编译,这意味着问题出在compressedString的in.push和到retString的副本上。我做错了什么吗?我不允许使用这样的字符串吗?

提前致谢

I'm having a problem with the zlib libraries in boost under VS 2010. I built the libraries and the appropriate dlls/libs were generated in the boost/stage/lib folder. I added the .dlls into my programs debug folder and linked in the matching.lib.

But I'm running into problems when I actually try to use the zlib streams. Heres an example:

#include <cstring>
#include <string>
#include <iostream>
#include <boost\iostreams\filter\gzip.hpp>
#include <boost\iostreams\filtering_streambuf.hpp>
#include <boost\iostreams\copy.hpp>
std::string DecompressString(const std::string &compressedString)
{
    boost::iostreams::filtering_streambuf<boost::iostreams::input> in;
    in.push(boost::iostreams::zlib_decompressor());
    in.push(compressedString);
    std::string retString = "";

    copy(in, retString);
    return retString;
}



when I try to compile thise though, I get multiple errors including:
error C2039: 'char_type' : is not a member of 'std::basic_string<_Elem,_Traits,_Ax>'    c:\program files (x86)\boost\boost_1_46_0\boost\iostreams\traits.hpp
error C2208: 'boost::type' : no members defined using this type c:\program files (x86)\boost\boost_1_46_0\boost\iostreams\traits.hpp
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int   c:\program files (x86)\boost\boost_1_46_0\boost\iostreams\traits.hpp

If I change my code to the following:

std::string DecompressString(const std::string &compressedString)
{

    boost::iostreams::filtering_streambuf<boost::iostreams::input> in;
    in.push(boost::iostreams::zlib_decompressor());
    std::string retString = "";
    return retString;

}

It compiles, meaning the problem is with the in.push for compressedString and the copy to the retString. Am I doing something wrong? Am I not allowed to use strings like this?

Thanks in advance

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

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

发布评论

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

评论(1

回首观望 2024-11-01 02:42:37

试试这个:

#include <string>
#include <iostream>
#include <sstream>
#include <boost\iostreams\filter\zlib.hpp>
#include <boost\iostreams\filtering_streambuf.hpp>
#include <boost\iostreams\copy.hpp>

std::string DecompressString(const std::string &compressedString)
{
    std::stringstream src(compressedString);
    boost::iostreams::filtering_streambuf<boost::iostreams::input> in(src);
    std::stringstream dst;
    boost::iostreams::filtering_streambuf<boost::iostreams::output> out(dst);
    in.push(boost::iostreams::zlib_decompressor());

    boost::iostreams::copy(in, out);
    return dst.str();
}

基本问题似乎是您尝试在字符串类型而不是流类型上使用boost::iostreams::copy()。此外,包含 zlib.hpp 而不是 gzip.hpp 可能也没有什么坏处。

Try this:

#include <string>
#include <iostream>
#include <sstream>
#include <boost\iostreams\filter\zlib.hpp>
#include <boost\iostreams\filtering_streambuf.hpp>
#include <boost\iostreams\copy.hpp>

std::string DecompressString(const std::string &compressedString)
{
    std::stringstream src(compressedString);
    boost::iostreams::filtering_streambuf<boost::iostreams::input> in(src);
    std::stringstream dst;
    boost::iostreams::filtering_streambuf<boost::iostreams::output> out(dst);
    in.push(boost::iostreams::zlib_decompressor());

    boost::iostreams::copy(in, out);
    return dst.str();
}

The basic problem seems to be that you're trying to use boost::iostreams::copy() on string types rather than stream types. Also, including zlib.hpp instead of gzip.hpp probably doesn't hurt either.

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