【发布时间】:2018-03-27 20:02:35
【问题描述】:
我正在尝试熟悉如何使用 boost::iostreams。查看 iostreams 教程,似乎这个测试代码应该是接收设备和流模板的简单实现:
#include <iostream>
#include <iosfwd>
#include <boost/iostreams/categories.hpp>
#include <boost/iostreams/stream.hpp>
#include <boost/iostreams/concepts.hpp>
namespace io = boost::iostreams;
class testSink {
public:
typedef char char_type;
typedef io::sink_tag category;
std::streamsize write(const char* s, std::streamsize n) {
std::cout.write(s, n);
return n;
}
};
int main(int argc, char *argv[])
{
io::stream<testSink> out;
out << "Hello" << std::endl;
return EXIT_SUCCESS;
}
在 linux 和 g++ (g++ (GCC) 4.8.5 20150623 (Red Hat 4.8.5-16)) 下编译它成功且没有错误,但运行它会因断言失败而崩溃:
/usr/local/include/boost/iostreams/detail/optional.hpp:55: T& boost::iostreams::detail::optional::operator*() [with T = boost::iostreams::detail ::concept_adapter]:断言“初始化_”失败。 中止(核心转储)
显然有一些未记录的初始化步骤,但是什么?
谢谢
【问题讨论】:
标签: c++ boost-iostreams