By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,680 Members | 1,578 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,680 IT Pros & Developers. It's quick & easy.

How do I delete lines from a file using "ofstream" ?

P: n/a

Hi everybody,
I am using the STL "ofstream" class.

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)

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
--
Ce message a ete poste via la plateforme Web club-Internet.fr
This message has been posted by the Web platform club-Internet.fr

http://forums.club-internet.fr/
Nov 13 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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

Nov 13 '05 #2

P: n/a
Paul LAURENT wrote:

I am using the STL "ofstream" class.


c.l.c++ is over thataway --------->

--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!
Nov 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.