gpt4 book ai didi

c++ - 使用boost解压文件

转载 作者:行者123 更新时间:2023-11-30 04:54:40 25 4
gpt4 key购买 nike

我想用 boost 解压一个用 bzip2 压缩过的文件

我尝试了以下导致我无法解释的错误

std::stringstream readData(const std::string path) {
std::stringstream myStream;
std::ifstream input(path,std::ios_base::in);

boost::iostreams::filtering_streambuf<boost::iostreams::input>in;
in.push(input);
in.push(boost::iostreams::bzip2_decompressor());
boost::iostreams::copy(in,myStream);

return myStream;
}

我使用 c++17、boost 1.58 和 gcc 8.0 编译上面的代码

并得到以下错误:

terminate called after throwing an instance of 'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injectorstd::logic_error >'
what(): chain complete

非常感谢有关如何解决此问题的任何帮助/提示

最佳答案

设备必须是您推送到 filtering_streambuf 的最后一个项目,在您推送设备之后,您将不能推送任何其他内容,这就是您收到错误的原因。参见 https://www.boost.org/doc/libs/1_68_0/libs/iostreams/doc/classes/filtering_streambuf.html#policy_push

您的代码应该是:

std::stringstream readData(const std::string path) {
std::stringstream myStream;
std::ifstream input(path,std::ios_base::in);

boost::iostreams::filtering_streambuf<boost::iostreams::input>in;
in.push(boost::iostreams::bzip2_decompressor());
in.push(input);
boost::iostreams::copy(in,myStream);

return myStream;
}

关于c++ - 使用boost解压文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53461495/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com