473,752 Members | 8,851 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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


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
2 8972
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.l earn.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
Paul LAURENT wrote:

I am using the STL "ofstream" class.


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

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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1833
by: Kashish | last post by:
Is file<<"Some string"<<endl is an atomic operation. where file is an ofstream object. If we output a string in ofstream and we provide endl after that,Can we make sure the whole string will be put in file at a time or the string can appear in parts.String lenfth is no more than 50 chars. I have 2 processes on different solaris boxes (NFS) running in parallel.one process writing lines to the file and other process reading lines from...
2
3508
by: Steven T. Hatton | last post by:
I'm still not completely sure what's going on with C++ I/O regarding the extractors and inserters. The following document seems a bit inconsistent: http://gcc.gnu.org/onlinedocs/libstdc++/27_io/howto.html#1 Copying a file: WRONG WAY: #include <fstream> std::ifstream IN ("input_file"); std::ofstream OUT ("output_file");
2
4228
by: mahurshi | last post by:
I am trying to read a file full of numbers followed by spaces (and then do some cool stuff with it) My input file looks like this 1 0 1 0 1 0 1 1 1 0 0 1 1 0
7
3373
by: clusardi2k | last post by:
Hello, I have a shared drive on SGI, Linux, and Windows. A second call to fopen doesn't create the file if it has been deleted. I would like to use fopen for its pointer return value to solve this. What is the best way to fix this problem?
4
12870
by: marathoner | last post by:
I tried your advice, and replaced "ifstream" with "std::ifstream". I also replaced instances of "ofstream" with "std::ofstream". Those syntax errors were resolved. When I added "std" to the following statement: m_InFile.open(m_sFileName, ios::in | ios::binary); which became m_InFile.open(m_sFileName, std::ios::in | std::ios::binary); I get the following errors:
5
5903
by: StephQ | last post by:
At the moment I have a void member function (of a given class) that takes as input an obj of class type ofstream and write some debug information to it using the << operator. I would like to modify the code so that the function returns a "stream" that can be "sent" to cout or to a file using <<, as this would give me more flexibility. I used " " because I'm not sure I'm not using the correct terms here. :P Is there an easy way to...
23
4867
by: mahesh | last post by:
Hi all, I have following code that is supposed to increase the power by specified value. int main() { system("cls"); int i, exponent; double base; double new_base=0.0;
4
1788
by: LewGun | last post by:
Usually, when we program with C++, we like to include the header"iostream", but it's too big, so i want to use the header "ostream" (only use it to output), as follows ,there is a piece of code what i think can do this.. but the compiler can't give me a good news. what can i do. //------------------------------------------------------------------ // source code //------------------------------------------------------------------...
2
2257
by: mauricesmith42 | last post by:
Sorry i know this is rather large to be posting, but in order to understand the question you have to see all the code //#include <windows.h> //needed for opening folders #include <stdlib.h> //needed for converting integers to strings #include <iostream> //needed for in/out commands ie. cin/cout #include <fstream> //needed to open readable/writeable files ie. ifstream/ofstream #include <string> //needed to create strings from...
0
9031
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9429
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9383
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9295
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8295
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6836
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4738
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2839
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2243
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.