gpt4 book ai didi

c++ - boost::iostream::filtering_streambuf 的编译错误

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

只是尝试使用 bzip2 压缩一个字符串,以便我可以使用 ReadFile 通过管道发送它。

以下行给我带来了以下编译错误。

in.push(uncompressed_string);

错误 6 error C2027: use of undefined type 'boost::STATIC_ASSERTION_FAILURE' c:\program files (x86)\boost\boost_1_47\boost\iostreams\chain.hpp 488 1 Agent

boost::iostreams::filtering_streambuf<boost::iostreams::input> in;
ostringstream uncompressed_string;
ostringstream compressed_string;


uncompressed_string << buf;

in.push(boost::iostreams::bzip2_compressor());
in.push(uncompressed_string);

boost::iostreams::copy(uncompressed_string, compressed_string);

最佳答案

错误是由于将输出流作为其设备插入输入过滤流。

#include <sstream>
#include <string>
//#include <boost/iostreams/filtering_stream.hpp>
#include <boost/iostreams/filtering_streambuf.hpp>
#include <boost/iostreams/filter/bzip2.hpp>
#include <boost/iostreams/copy.hpp>
int main()
{
std::string buf = "this is a test\n";

//boost::iostreams::filtering_istream in; // I think this is simpler
boost::iostreams::filtering_streambuf<boost::iostreams::input> in;
in.push(boost::iostreams::bzip2_compressor());
std::istringstream uncompressed_string(buf);
// in.push(boost::make_iterator_range(buf)); // another option
in.push(uncompressed_string);
std::ostringstream compressed_string;
boost::iostreams::copy(in, compressed_string);

std::cout << compressed_string.str();
}

使用 gcc 4.6.1 和 boost 1.46 测试

~ $ ./test | bzcat
this is a test

关于c++ - boost::iostream::filtering_streambuf 的编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7880236/

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