C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old November 19th, 2004, 09:53 AM
s4kk3 s4kk3 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 2 s4kk3 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Need little help deleting lines from file

I'm making a small todo program. It only misses one important thing. Removin line from txt file. This is what I want it to do:

I add few todo's with this program. Like:

Quote:
Do homeworks
Go out
When I have done my homeworks I want remove that file. How should that be done. Google havn't been my friend with this.

If you want to see that code I can paste it here.

Reply With Quote
  #2  
Old December 5th, 2004, 02:13 AM
Evoltix Evoltix is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Location: Nebraska
Posts: 14 Evoltix User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to Evoltix Send a message via Yahoo to Evoltix
I might be able to help. Please paste the code so I can see.

Reply With Quote
  #3  
Old December 9th, 2004, 11:07 AM
s4kk3 s4kk3 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 2 s4kk3 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Here it is. Haven't figured it out yet. I have gotten it to read the first line from the file with getline but it doesn't do the trick(not in this code).

Quote:
#include <iostream>
#include <fstream>
#include <stdlib.h>
using namespace std;

int main ()
{

int option;

while (exit) {

cout<<"\nCurrently available options:\n\n 1 shows your todo list \n 2 add note to your list \n 3 clear your list \n 4 quit \n\n";
cout <<"What is your choice: "; cin >> option;
cin.ignore();

if ( option == 1 )
{
char show[256];
ifstream todofile ("todo.txt");
if (! todofile.is_open())
{
cout << "Error opening file";
}

while (! todofile.eof() )
{
todofile.getline (show,100);
cout << "\n\n\n" << show << endl;
}

}
if ( option == 2 )
{
{
char add[256];
ofstream todofile ("todo.txt",ios::app);
if (todofile.is_open())
{
cout << "Insert note: ";
cin.getline(add,256);
todofile << add <<"\n" ;
}

}
}

if ( option == 3 )
{
cout << "\n Your TODO list have been cleared \n \n";
ofstream todofile ( "todo.txt",ios::trunc );
}

if ( option == 4 )
{
cout <<"\n Bye Bye!! \n\n";
return 0;
}

}
return 0;

}
As you can see it truncates whole file. It's not very good option.

Reply With Quote
  #4  
Old December 9th, 2004, 09:39 PM
marmo marmo is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 37 marmo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 15 m 20 sec
Reputation Power: 4
You could try reading the file into a string object, then use the erase member function to delete the lines you want removed. Once you have it looking the way you want overwrite the old text file using the new string.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Need little help deleting lines from file


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway