boost :: iostream :: filtering_streambuf的编译错误

时间:2011-10-24 18:40:21

标签: c++ boost boost-iostreams

尝试使用bzip2压缩字符串,以便我可以通过具有ReadFile的管道发送它。

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

in.push(uncompressed_string);

错误6错误C2027:使用未定义类型'boost :: STATIC_ASSERTION_FAILURE'c:\ program files(x86)\ boost \ boost_1_47 \ boost \ iostreams \ chain.hpp 488 1代理

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

1 个答案:

答案 0 :(得分:2)

该错误是由于将输出流推送到输入过滤流作为其设备。

#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测试并增强1.46

~ $ ./test | bzcat
this is a test