通过boost追加到现有文件
Appending to existing file via boost
我需要将许多日志文件聚合到一个日志中。
我曾尝试使用boost::filesystem::copy_file来完成此操作,但它不支持追加。
有什么想法吗?(我更喜欢通过boost库来做这件事)
Tnx
这个简单的任务不需要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();
//...
(但请注意,上述方法可能具有次优性能;请查看此答案以了解如何提高性能。)
相关文章:
- boost::文件系统::recursive_directory_iterator多线程安全
- 使用 Boost.Spirit 解析具有混合数据类型的 OBJ 文件?
- 避免使用 boost::进程间::消息队列创建文件
- 使用Boost文件系统C++将具有特定扩展名的文件的名称保存在特定文件夹中
- Boost program_options将多个配置文件解析结果存储到一个parsed_options中
- 告诉CMake链接到自定义文件夹中的Boost
- 致命错误:找不到'boost/uuid/uuid.hpp'文件
- 使用boost::mapped_region增长文件以供进一步写入?
- 造成致命错误:boost/fusion/iterator/equal_to.hpp 没有这样的文件或目录
- 通过boost asio iostream下载大文件的最快方法是什么?
- 将 boost::文件系统::p ath 转换为 char?
- 使用 boost::regex 从目录中获取带有一些正则表达式的文件名称时出现意外输出
- 可以将Boost消息队列文件重定向到用户指定的位置
- boost::p rogram_options 配置文件格式
- 如何在Boost::program_options配置文件中为非字符串的自定义选项值类型处理空格
- boost日志文件无法创建sample.log文件
- 如何修复"无法打开包含文件'boost/config.hpp':没有这样的文件或目录(包括目录涵盖:C:\程序文件\boost\boost_1_67_0)
- C 可以在程序执行过程中移动内存映射的文件(boost :: intercecess)移动
- 包括cmake头文件boost.hpp和cmake
- 查找最后添加的文件(boost)