用boost写入一个gz流
writing a gz stream with boost
我编写了一段代码,使用boost
将输出写入gz
文件。
class foo() {
std::ofstream traceOut;
struct traceRec {
traceRec(uint64_t c) : cycle(c) {};
uint64_t cycle;
};
void writeTrace(traceRec &rec)
{
try {
boost::iostreams::filtering_istream in;
in.push(boost::iostreams::gzip_decompressor());
in.push(traceOut); // ERROR
std::cout << rec.cycle << std::endl;
}
catch(const boost::iostreams::gzip_error& e) {
std::cout << e.what() << 'n';
}
}
void init() {
traceOut.open("log.gz", std::ios_base::in | std::ios_base::binary);
}
void bar() {
traceRec rec (1000);
writeTrace(rec);
}
};
但是我在编译
时得到这个错误/opt/boost_1_33_1/boost/iostreams/chain.hpp: In member function ‘void boost::iostreams::detail::chain_client<Chain>::push(std::basic_ostream<_CharT2, _Traits2>&, int, int) [with CharType = char, TraitsType = std::char_traits<char>, Chain = boost::iostreams::chain<boost::iostreams::input, char,
std::char_traits<char>, std::allocator<char> >]’:
test.cpp: instantiated from here
/opt/boost_1_33_1/boost/iostreams/chain.hpp:472: error: invalid application of ‘sizeof’ to incomplete type ‘boost::STATIC_ASSERTION_FAILURE<false>’
/opt/boost_1_33_1/boost/iostreams/traits.hpp: At global scope:
/opt/boost_1_33_1/boost/iostreams/traits.hpp: In instantiation of ‘boost::iostreams::detail::member_category<mpl_::void_>’:
/opt/boost_1_33_1/boost/mpl/eval_if.hpp:38: instantiated from ‘boost::mpl::eval_if<boost::iostreams::is_std_io<mpl_::void_>, boost::iostreams::select<boost::iostreams::is_iostream<mpl_::void_>, boost::iostreams::iostream_tag, boost::iostreams::is_istream<mpl_::void_>, boost::iostreams::istream_tag, boost::iostreams::is_ostream<mpl_::void_>, boost::iostreams::ostream_tag, boost::iostreams::is_streambuf<mpl_::void_>, boost::iostreams::streambuf_tag, mpl_::bool_<true>, mpl_::void_, mpl_::bool_<true>, mpl_::void_, mpl_::bool_<true>, mpl_::void_, mpl_::bool_<true>, mpl_::void_, mpl_::bool_<true>, mpl_::void_, mpl_::bool_<true>, mpl_::void_>, boost::iostreams::detail::member_category<mpl_::void_> >’
....
那是什么意思?
请看这个,push()方法必须接收流而不是任意对象
EDIT1(以下评论交换)
将traceOut
类型更改为std::ifstream
解决了构建问题(至少使用boost 1.52)
相关文章:
- 如何创建一个CMake变量,除非显式重写,否则使用默认值
- 删除一个线程上有数百万个字符串的大型哈希映射会影响另一个线程的性能
- 为什么两个不同的未命名名称空间可以共存于一个cpp文件中
- 运行同一解决方案的另一个项目的项目
- 挂起和取消挂起一个文件DLL
- 用C++中的一个变量定义一个常量
- 函数向量_指针有不同的原型,我可以构建一个吗
- 在c++中用vector填充一个简单的动态数组
- 如何在选项卡视图Qt中设置一个新项目,并保存以前的项目
- 预处理器:插入结构名称中的前一个行号
- 我在c++代码中生成了一个运行时#3异常
- 我想将一个对T类型的非常量左值引用绑定到一个T类型的临时值
- 从链接列表c++中删除一个项目
- 告诉一个 const char 数组,除了编译时 C 样式的字符串外,它不以 '