C++ BOOST.IOstreams:写入bzip2很麻烦
您好,我想使用Boost.IOstreams将数据存储到bzip2文件中C++ BOOST.IOstreams:写入bzip2很麻烦,c++,boost-iostreams,bzip2,C++,Boost Iostreams,Bzip2,您好,我想使用Boost.IOstreams将数据存储到bzip2文件中 void test_bzip() { namespace BI = boost::iostreams; { string fname="test.bz2"; { BI::filtering_stream<BI::bidirectional> my_filter; my_filter.push(BI::combine(BI::bzip2_decompressor(), BI::bzip2_c
void test_bzip()
{
namespace BI = boost::iostreams;
{
string fname="test.bz2";
{
BI::filtering_stream<BI::bidirectional> my_filter;
my_filter.push(BI::combine(BI::bzip2_decompressor(), BI::bzip2_compressor())) ;
my_filter.push(std::fstream(fname.c_str(), std::ios::binary|std::ios::out)) ;
my_filter << "test" ;
}//when my_filter is destroyed it is trowing an assertion.
}
};
void test_bzip()
{
名称空间BI=boost::iostreams;
{
字符串fname=“test.bz2”;
{
BI::过滤\u流我的\u过滤器;
my_filter.push(BI::combine(BI::bzip2_decompressor(),BI::bzip2_compressor());
my_filter.push(std::fstream(fname.c_str(),std::ios::binary | std::ios::out));
my_filter无法复制fstream
,因此您必须使用push的参考版本
template<typename StreamOrStreambuf>
void push( StreamOrStreambuf& t,
std::streamsize buffer_size = default value,
std::streamsize pback_size = default value );
我很惊讶你的编译器允许你的代码,我想它会抱怨引用了临时…你使用的是哪种编译器?@Pieter:我使用的是VC++2008 Express edition:Version 9.0.30729.1 SP。代码在没有任何警告的情况下顺利编译。你的建议没有解决问题。与以前一样,它停止于:void bzip2_base::end(bool compress)在iostreams/src/bzip2.cpp函数中。在我看来,您已经到了需要转到boost邮件列表的地步。@本·柯林斯:是的,我就是这么做的。谢谢。第二个代码段也没有用gcc.my_filter.push(std::fstream(…)编译“没有匹配的函数”@epronk:它是什么编译器?我使用gcc 4.4.4:g++bz_test.cpp-I${BOOSTROOT}/include-L${BOOSTROOT}/lib-lboost_iostreams,它编译起来没有问题。我刚刚编辑了帖子。你解决了这个问题吗?如果是的话,请发布一个答案。@Cookie:看看编辑,这很有效。
template<typename StreamOrStreambuf>
void push( StreamOrStreambuf& t,
std::streamsize buffer_size = default value,
std::streamsize pback_size = default value );
std::fstream theFile(fname.c_str(), std::ios::binary | std::ios::out);
// [...]
my_filter.push(theFile) ;