Thread: Delete a line in a file

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    9

    Delete a line in a file

    Hi,

    I'm trying to delete a line in a file, but I'm not succeeding very well... Here is my function:
    Code:
    void deleteLine( int id )
    {
    	string contents;
    	int i = 1;
    	
    	ifstream file ( "file.txt" );
    	
    	while ( file.good() )
    	{
    		if ( i != id )
    		{
    			contents = sprintf("%s%s", contents, file.getline() );
    		}
    		i++;
    	}
    	
    	file.close();
    	
    	ofstream file ( "file.txt" );
    	
    	file << contents;
    	
    	file.close();
    }
    I get an error on contents = sprintf... Do you see any directly errors or shell I show my error messages too?

    Yours, @nders.
    Last edited by @nders; 12-30-2004 at 02:43 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Basic text file encoder
    By Abda92 in forum C Programming
    Replies: 15
    Last Post: 05-22-2007, 01:19 PM
  2. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  3. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  4. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM