使用boost解压缩文件

XPenguen

我想使用已使用bzip2压缩的boost来解压缩文件

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

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;
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章