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

Staff online

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,161
Latest member
GertrudeMa
Top