Delete chars in a file stream

Discussion in 'C++' started by Bernie, Jun 13, 2008.

  1. Bernie

    Bernie Guest

    Hi

    How can I remove/delete the last n characters from a fstream object?

    Thanks
    Bernie
    Bernie, Jun 13, 2008
    #1
    1. Advertising

  2. Bernie

    James Kanze Guest

    On Jun 13, 10:40 am, "Bernie" <indico(at)gmx-topmail.de> wrote:
    > How can I remove/delete the last n characters from a fstream object?


    You can't.

    First of all, of course, an fstream doesn't contain any
    characters; it is only an interface to an external file which
    contains the characters. But there's no standard way of
    truncating a file, either (and some OS's don't support it at
    all). The usual solution is to copy the file to a new file,
    without copying what shouldn't be copied. There will often be
    an OS specific means of truncating the file as well, but you
    can't use it on an fstream; you'll have to check with your OS
    documentation for more information there.

    --
    James Kanze (GABI Software) email:
    Conseils en informatique orient�e objet/
    Beratung in objektorientierter Datenverarbeitung
    9 place S�mard, 78210 St.-Cyr-l'�cole, France, +33 (0)1 30 23 00 34
    James Kanze, Jun 13, 2008
    #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. Sakagami Hiroki

    mix chars and bytes in a stream.

    Sakagami Hiroki, Aug 6, 2006, in forum: Java
    Replies:
    7
    Views:
    452
    Oliver Wong
    Aug 31, 2006
  2. Kosio

    Floats to chars and chars to floats

    Kosio, Sep 16, 2005, in forum: C Programming
    Replies:
    44
    Views:
    1,285
    Tim Rentsch
    Sep 23, 2005
  3. lovecreatesbeauty
    Replies:
    17
    Views:
    593
    Jordan Abel
    Jan 1, 2006
  4. Hongyu
    Replies:
    9
    Views:
    902
    James Kanze
    Aug 8, 2008
  5. M.Posseth

    receiving ??? chars instead of "special" chars

    M.Posseth, Nov 15, 2004, in forum: ASP .Net Web Services
    Replies:
    3
    Views:
    225
    Dan Rogers
    Nov 16, 2004
Loading...

Share This Page