Re: How do I delete lines from a file using "ofstream" ?
From: Thomas Matthews (Thomas_MatthewsHatesSpam_at_sbcglobal.net)
Date: 11/06/03
- Next message: maniac: "Re: "Mastering C Pointers"...."
- Previous message: Glen Herrmannsfeldt: "Re: Binary executable format for new language"
- Next in thread: CBFalconer: "Re: How do I delete lines from a file using "ofstream" ?"
- Maybe reply: CBFalconer: "Re: How do I delete lines from a file using "ofstream" ?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 06 Nov 2003 21:12:41 GMT
Paul LAURENT wrote:
> Hi everybody,
>
>
> I am using the STL "ofstream" class.
There is no STL, ofstream, or class in standard C. You may want the
folks across the hall in news:comp.lang.c++.
{However, the answer to your issue is still the same, see below}.
> I open a file using "ofstream" in update at the end mode ("ate"), I can read and
> write my file correctly.
>
> => What I would like to do is deleting some lines from the file which decreases
> the size of the file.
>
> For performance reasons, I DO NOT WANT to close and open the file each time I
> want to delete some information in it (I know that you can overwrite the file
> content by re-opening the file)
Yes, but overwriting does not guarantee adjusting the end of the file to
the last used record.
> I only found methods which allow you to add some information but no methods for
> deleting the information.
>
> Any idea will be welcome !
>
>
>
> Thanks in advance.
>
>
>
> Paul
>
>
Unfortunately, there is no process in _standard_ C to truncate a file
by delete portions of it. The portable method is to copy the portions
of the old file to a new file and then delete the old file {you could
rename the new file at this point}.
However, your platform may have some specific functions to perform
what you want. Ask the experts in a newsgroup about your platform.
--
Thomas Matthews
C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book
- Next message: maniac: "Re: "Mastering C Pointers"...."
- Previous message: Glen Herrmannsfeldt: "Re: Binary executable format for new language"
- Next in thread: CBFalconer: "Re: How do I delete lines from a file using "ofstream" ?"
- Maybe reply: CBFalconer: "Re: How do I delete lines from a file using "ofstream" ?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|