【发布时间】:2017-12-05 22:50:24
【问题描述】:
从boost iostreams tutorial 我读到可以将 boost stream_buffer 与 std::ostream 一起使用,如教程中所示:
#include <ostream>
#include <boost/iostreams/device/file.hpp>
#include <boost/iostreams/stream.hpp>
namespace io = boost::iostreams;
int main()
{
io::stream_buffer<io::file_sink> buf("log.txt");
std::ostream out(&buf);
// out writes to log.txt
}
我们如何使用 boost stream_buffer 来创建 std::ofstream?我已经实现了一个自定义接收设备,我可以用它来创建一个 boost stream_buffer。使用流缓冲区,我可以创建 std::ostream,但不能创建 std::ofstream。
// ...
io::stream_buffer<my_custom_file_sink> mybuf("myfile.txt"); // Creating stream_buffer works
std::ostream out(&mybuf); // Here I would like to use std::ofstream
// ...
我需要这个,因为我正在使用的另一个库需要 std::ofstream&。但不幸的是,将 boost stream_buffer 传递给 std::ofstream 构造函数无法编译。任何可能的解决方法?
【问题讨论】:
-
没有。没有解决方法。
-
@noxmetus 你会感到惊讶的。
标签: c++ boost stl ofstream ostream