truncate end of file

Discussion in 'C++' started by Natevw, Nov 3, 2004.

  1. Natevw

    Natevw Guest

    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
     
    Natevw, Nov 3, 2004
    #1
    1. Advertising

  2. 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
     
    Victor Bazarov, Nov 3, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    4
    Views:
    517
    Jack Klein
    Jun 5, 2004
  2. Amit Kulkarni

    HOW-TO Truncate first line in a file to zero length?

    Amit Kulkarni, Jun 22, 2004, in forum: C Programming
    Replies:
    4
    Views:
    3,660
    dbtid
    Jun 23, 2004
  3. Jimmy
    Replies:
    3
    Views:
    330
    J. J. Farrell
    Sep 9, 2011
  4. Jimmy
    Replies:
    13
    Views:
    654
    Peter Nilsson
    Sep 21, 2011
  5. Leslie Viljoen

    File#truncate fills file with zeros

    Leslie Viljoen, Nov 16, 2010, in forum: Ruby
    Replies:
    1
    Views:
    140
    Leslie Viljoen
    Nov 16, 2010
Loading...

Share This Page