次のコードを使用して、ブースト内のgzipされた文字列を解凍しようとしています
std::string DecompressString(const std::string &compressedString)
{
std::stringstream src(compressedString);
if (src.good())
{
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();
}
return "";
}
ただし、この関数を呼び出すたびに (以下のように)
string result = DecompressString("H4sIA");
string result = DecompressString("H4sIAAAAAAAAAO2YMQ6DMAxFfZnCXOgK9AA9ACsURuj9N2wpkSIDootxhv+lN2V5sqLIP0T55cEUgdLR48lUgToTjw/5zaRhBuVSKO5yE5c2kDp5zunIaWG6mz3SxLvjeX/hAQ94wAMe8IAHPCwyMS9mdvYYmTfzdfSQ/rQGjx/t92A578l+T057y1Ff6NW51Uy0h+zkLZ33ByuPtB8IuhdcnSMIglgm/r15/rtJctlf4puMt/i/bN16EotQFgAA");
プログラムは常にこの行で失敗します
in.push(boost::iostreams::zlib_decompressor());
次の例外を生成します
Unhandled exception at 0x7627b727 in KHMP.exe: Microsoft C++ exception:
boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<std::logic_error> > at memory location 0x004dd868..
これについてはまったくわかりません...誰か提案はありますか?
ありがとう
編集:
提案に従って、コードを次のように切り替えます
boost::iostreams::filtering_streambuf<boost::iostreams::input> in;//(src);
in.push(boost::iostreams::zlib_decompressor());
in.push(src);
std::stringstream dst;
boost::iostreams::filtering_streambuf<boost::iostreams::output> out;//(dst);
out.push(dst);
boost::iostreams::copy(in, out);
ただし、コピー時に発生することを除いて、例外は引き続き発生します