2

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

Megatron
  • 2,871
  • 4
  • 40
  • 58
  • `char_type` most certainly should be a member of `std::basic_string<_Elem, _Traits, _ax>`. The errors you're getting appear to be related to declaring the type of `in` incorrectly. Unfortunately, I don't have enough experience with Boost.Iostreams to say what it should be declared as, and I'll have to leave that to another commenter. I find the interface given by zlib to be easy enough to work with by itself. – Max Lybbert Mar 21 '11 at 17:23

1 Answers1

1

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.

Ferruccio
  • 98,941
  • 38
  • 226
  • 299
  • Thansk for the suggestion, but unfortuantely, doing this causes boost to throw an exception: Unhandled exception at 0x7627b727 in KHMP.exe: Microsoft C++ exception: boost::exception_detail::clone_impl > at memory location 0x002cd770.. – Megatron Mar 21 '11 at 19:18