Question: I am using ofstream to output some text to a file in `ios::app` mode within a loop. But after some step, I need to clear the content of the file. I know we can do it by either delete the file and open again or to open it again with `ios::trunc`, but is there any where I can get it done without close and open the file again?

Answer: 
If you have opened it in `ios::app` mode, there's no way to clear content without opening it again. `ofstream` can only put text in a file, and as text files are sequential, you can't directly erase data on them.
Note sure if it is possible with io streams, but in general you can truncate an open file by setting its current position to 0 and then setting the EOF marker on the file. In the Win32 API, for instance, you can do that with `SetFilePointer()` and `SetEndOfFile()`.