jeudi 27 avril 2017

Writing "\r" with std::cout to file saves previously overwritten lines

I'm running simulations using C++, and to track the simulation progress I'm writing outputs as std::cout << "\rSimulation progress: " << progress;, as per this answer http://ift.tt/2oMgE6u. So with "\r" I thought I was overriding the previous line, but when I save the output to log files, the previously overridden lines are saved as well, with a ^M before each instance of the "overridden" lines. Now I have log files that are around 100MB when they would only need to be a few KB.

An example of what the file looks like:

^MSimulation progress: 66.500^MSimulation progress: 66.600^MSimulation 
progress: 66.700^MSimulation progress: 66.800^MSimulation progress: 
66.900^MSimulation progress: 67.000^MSimulation progress: 67.100^MSimulation 
progress: 67.200^MSimulation progress: 67.300

What I want for this line is only the last instance

Simulation progress: 67.300

Is there a good way or a standard way to remove the lines for real?

Thanks!

Aucun commentaire:

Enregistrer un commentaire