c++ - 通过 boost append 到现有文件

标签 c++ boost append iostream boost-filesystem

我需要将许多日志文件聚合到一个日志中。

我试着用 boost::filesystem::copy_file 来做这个,但它不支持追加。

有什么想法吗? (我更喜欢通过 boost 库来做到这一点)

谢谢

最佳答案

这个简单的任务不需要 Boost - 标准的 iostream 就可以完成这项工作:

#include <fstream>
//...
using std::ifstream;
using std::ofstream;
ifstream input1("input1.log"), input2("file2.log");
// append to an existing file
ofstream output("output.log", ofstream::out | ofstream::app);
output << input1.rdbuf() << input2.rdbuf();
//...

(但请注意,上述方法的性能可能不理想;查看 this answer 以了解如何 boost 性能。)

关于c++ - 通过 boost append 到现有文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23347415/

相关文章:

javascript - 在 D3 中 append 堆叠条形图和另一个条形图

python - 为什么这段代码不能无限运行?

c++ - 初始化字符串指针数组并通过函数调用打印相同的内容不起作用,为什么?

c++ - 声明嵌套命名空间 `std` 是否合法 C++?

c++ - 使用boost将gzip压缩/解压缩到内存中

c++ - 正则表达式帮助,匹配产生额外的空格

c# - 在 ubuntu 操作系统中从单声道调用 g++

c++ - bool 数组获取意外的默认值

c++ - 同步 boost ASIO : Asynchronous write,

Android 将文件 append 到 zip 文件而不必重新编写整个 zip 文件?