gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 11:34:36 24 4
gpt4 key购买 nike

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

我试着用 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com