I’m writing a program that generates a large log file (+10GB) on completion. To split this up, in my logging function I redirect output to a new file name once n lines have been written.
However, some lines in this file can be huge (+100k chars) and some are no more than 10 chars, and the large ones can be clustered. I would much rather split the output by size in bytes rather than by line.
What’s the most lightweight method for keeping an ongoing track of the number of bytes that have been sent to a c++ stream?
If you’re using a
std::ostream, have a look at thetellp()member function, which returns the current position of the put area. You can use it as a proxy for the number of bytes written. E.g.:Also note though that
tellpflushes the tied output streams since C++11.