truncate end of file

N

Natevw

I am using <fstream> to write files in binary mode.
Is there any way I can force the file to end at a certain offset, without
rewriting the whole file? I could open the file with ios::trunc, but then I
have to copy into memory or tempfile everything I want to keep. I just want
to truncate everything after the write pointer. Can this be done?
-nate
 
V

Victor Bazarov

Natevw said:
I am using <fstream> to write files in binary mode.
Is there any way I can force the file to end at a certain offset, without
rewriting the whole file? I could open the file with ios::trunc, but then I
have to copy into memory or tempfile everything I want to keep. I just want
to truncate everything after the write pointer. Can this be done?

Not using standard means, I'm afraid. Your OS probably has some mechanism
to do what you want. For example, on UNIX, e.g., there is the 'truncate'
function...

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,992
Messages
2,570,220
Members
46,805
Latest member
ClydeHeld1

Latest Threads

Top