The only way that can be done is to rewrite the entire file. One way is to read everything into an array, or vector, or strings, then reopen the file for writing. Rewrite all the strings except the one you want to delete.
Since the lines contain other stuff you might want to use getline() as you originally posted. Then replace if(line == fruit) with this: if( line.find(fruit) != string::npos)
>> while(file->getline(line,size) != NULL)
Recode that like this: while( getline(file,line) ) if you make line a std::string instead of char*
Last edited by Ancient Dragon; Feb 7th, 2010 at 2:39 pm.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2280
Retired and Enjoying Life
Online 21,936 posts
since Aug 2005