Writing EOF into an output stream
Posted on 2004-11-12
Is there anyway to insert an EOF into an output stream to truncate the underlying file?
I have code that reads a five-line text file in with ifstream, closes it, opens a stream for output with ofstream on the same file, writes out the first four lines read in, and closes the output stream. I want the file to be terminated after the fourth line I write back out, but the EOF for the file hasn't moved, so that displaying the file with notepad still shows all five lines. How can I truncate this file at the end of my write?