Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > truncate end of file

Reply
Thread Tools

truncate end of file

 
 
Natevw
Guest
Posts: n/a
 
      11-03-2004
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


 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      11-03-2004
Natevw wrote:
> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is a blank at the end of a C file a better style than a newline atthe end of the file or is it better to place none? Jimmy C Programming 13 09-21-2011 12:17 AM
Is a blank at the end of a C file a better style than a newline atthe end of the file or is it better to place none? Jimmy C Programming 3 09-09-2011 10:36 PM
File#truncate fills file with zeros Leslie Viljoen Ruby 1 11-16-2010 10:22 PM
HOW-TO Truncate first line in a file to zero length? Amit Kulkarni C Programming 4 06-23-2004 01:49 AM
how to truncate a file jkherciueh@gmx.net C++ 4 06-05-2004 04:43 AM



Advertisments