473,804 Members | 3,424 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to delete a line from the file

I am a student doing internship. Iam doing a project.
I need to remove or update a line in the file.
So far
1.I can read from file
2. I can write to the file
3. I can find the string in the file i want to delete

Now,I want to take the input from one file and write all the infomation
to the new file except the one i don't want.
I can take the infrmation frm one file and write it to the new file and
delete the old file.

The only and imp bit i can't figure out is how to write all the
information except the one i dnt want
Would be something like

strncmp()
if(found)
here i want to write something that if found dnt write to new file
else
file<<all the lines;

Please help!!

Jul 26 '06 #1
1 8751

"ricky" <ri*******@yaho o.co.inwrote in message
news:11******** **************@ 75g2000cwc.goog legroups.com...
>I am a student doing internship. Iam doing a project.
I need to remove or update a line in the file.
So far
1.I can read from file
2. I can write to the file
3. I can find the string in the file i want to delete

Now,I want to take the input from one file and write all the infomation
to the new file except the one i don't want.
I can take the infrmation frm one file and write it to the new file and
delete the old file.

The only and imp bit i can't figure out is how to write all the
information except the one i dnt want
Would be something like

strncmp()
if(found)
here i want to write something that if found dnt write to new file
else
file<<all the lines;

Please help!!
#include <fstream>
#include <istream>
#include <iostream>
#include <ostream>
#include <string>

void omit(std::istre am& in, std::ostream& out, const std::string s)
{
static std::string line;
while(std::getl ine(in, line))
if(line != s)
out << line << '\n';
}

int main()
{
const std::string in_name("input. txt");
const std::string out_name("outpu t.txt");

std::ifstream input(in_name.c _str());
std::ofstream output(out_name .c_str());

if(!input)
std::cerr << "Cannot open input\n";

if(!output)
std::cerr << "Cannot open output\n";

if(input && output)
omit(input, output, "remove me");

if(!input.eof() )
std::cerr << "Error reading input\n";

if(!output)
std::cerr << "Error writing output\n";

return 0;
}
-Mike
Jul 26 '06 #2

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

Similar topics

5
5251
by: | last post by:
Hi all, I've been using C++ for quite a while now and I've come to the point where I need to overload new and delete inorder to track memory and probably some profiling stuff too. I know that discussions of new and delete is a pretty damn involved process but I'll try to stick to the main information I'm looking for currently. I've searched around for about the last too weeks and have read up on new and overloading it to some extent but...
5
18587
by: ad | last post by:
I want to delete some text which begin with <!DOCTYPE and end with > in a file. How can I do it?
6
2587
by: I am Sam | last post by:
I keep getting this error and I don't know why: The path is too long after being fully qualified. Make sure path is less than 260 characters. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.IO.PathTooLongException: The path is too long
6
2366
by: santa19992000 | last post by:
I have a file called xyz.txt, if the first word matches, I have to delete the whole line, how can I do that. sample is below file xyz.txt ======= SP 0/23/2345/345 CL 00/34/3456/54 In the above file, if the first word "SP" matches, then I have to delete the whole line in that file, How to delete. Thanks.
3
4660
by: silver360 | last post by:
Hello, I'm trying to create a basic Heap manager and i have some question about new/delete overloading. The following code give me this output : >> $./heap >> registered : 0x804d098 >> 0x804d008 _Delete unknown block >> registered : 0x804d138 >> 0x804d008 _Delete unknown block >> 0x804d098 _Delete ok
9
10285
by: groleo | last post by:
Hi list. Simple question: is it possible to override the global new/delete operators, without using malloc/free? I mean something in the ideea of the code below, which doesnt work cause of the recursivenes. What I'm trying to say is how to override new/delete using the original global
9
7040
by: Juergen Huber | last post by:
hello, i am a dummy user in python and new in this programming language and so there will be questions, that´s for you no problem! i never have before programmed in any language! sorry for this! i hope you will help me, that i also could the basics in this language! and later many more, so i hope ! :) the first question for me in this newsgroup will be the follow one: - is there a way to delete in a csv-file the first line?!
4
5575
by: jeepers | last post by:
Hi all, my problem is delete a line in a text file. the file contain -n line with user, userCode. i want to replace the line with user is egual at user, and/or insert new line but delete the line like user. i'm sorry for my english :D if user exist delete a line of the user and insert new line. if not exist insert new line. possibility to delete a line.
10
12228
by: Joah Senegal | last post by:
Hello all, I want something that should be realy really simple.... but I dont get it.. searched google and stuf, but found nothing useful. I;m opening a txt-file with a fstream. Now I want to make a function that looks like Removeline(int Linenumber); But I can;t get it working.. anybody has anything helpfull? if anybody can help me that would be great :D
2
19760
by: Francesco Pietra | last post by:
Please, how to adapt the following script (to delete blank lines) to delete lines containing a specific word, or words? f=open("output.pdb", "r") for line in f: line=line.rstrip() if line: print line f.close()
0
9589
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10340
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
10329
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
10085
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...
1
7626
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
5527
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...
0
5663
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3830
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3000
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.