1

I need to aggregate many log files into a single log.

I tried to do this with boost::filesystem::copy_file but it doesn't support appending.

Any ideas? (I'm preferring doing this via boost libraries)

Tnx

Mike Kinghan
  • 55,740
  • 12
  • 153
  • 182
o.z
  • 1,086
  • 14
  • 22

1 Answers1

1

You don't need Boost for this simple task - the standard iostream will do the job:

#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();
//...

(Note however that the above approach may have suboptimal performance; take a look at this answer to see how to improve the performance.)

Community
  • 1
  • 1
Igor R.
  • 14,716
  • 2
  • 49
  • 83