문제

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

도움이 되었습니까?

해결책

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.)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top