compile error for boost::iostream::filtering_streambuf

巧了我就是萌 提交于 2019-12-24 09:58:25

问题


Just trying to compress a string with bzip2 so that I can send it over a pipe with ReadFile.

The following line earns me the following compile error.

in.push(uncompressed_string);

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

回答1:


The error was due to pushing an output stream into an input filtering stream as its Device.

#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();
}

tested with gcc 4.6.1 and boost 1.46

~ $ ./test | bzcat
this is a test


来源:https://stackoverflow.com/questions/7880236/compile-error-for-boostiostreamfiltering-streambuf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!