Hello,
I am trying to log my program's average iterations per second, and I made it output to log.txt, but because it is an average, I want it to overwrite the file each time it writes to it. ios::trunc does not work, because that clears the file when I open it, but what I want is to clear it continually not just once. Does anyone know of a way to do this, or is it not possible?
If you mess around with set and tell members (That is what they are called right?) you could theoretically move back to the start of the fstream and then write to the beginning. Whether or not it erases I cannot say.
I'm confused as to why you'd want to keep overwriting the average, while your program is running. Couldn't you just keep track of the average while the program is running, and then write the final value to the text file after the completion of the program?
Perhaps I'm misunderstanding the nature of the question?
I suppose I could just keep track of the average and write it at the end, but I am really more interested in learning how to do it in case I need to later on.