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
Try this:
The basic problem seems to be that you're trying to use
boost::iostreams::copy()
on string types rather than stream types. Also, includingzlib.hpp
instead ofgzip.hpp
probably doesn't hurt either.