Thread: deleting files?

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    9

    Question deleting files?

    Hi people,
    just started programming bout a week ago and need a little help with some file i/o
    what i have done so far is use fstream to open save and then close a file in which the user types the filename and its contents but i have no idea how to delete the file any help??

    cheers in advance

  2. #2
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    You can use remove(char* filename) to do this task.

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    9
    thanx for the help but i cannot remove(char* filename) to work
    here is some of my code

    Code:
    	ofstream file;
    		file.open(fileName);
    
    		file<<firstName<<"\n"
    			<<lastName<<"\n"
    			<<phoneNumber<<"\n"
    			<<mobilePhone<<"\n"
    			<<emailAddress<<"\n";
    
    		file.close();
    
    	return menu();
    } 
    
    int deleteContact()
    {
    	file.remove("blah.txt");
    
    	return menu();
    }
    i know i am useing it totaly wrong, any help on how to implament it?

    thanx

  4. #4
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    remove() is not a ofstream member function, if you include <cstdio> it will be a global function so you can call it like this -

    int deleteContact()
    {
    remove("blah.txt");

    return menu();
    }


    assuming that blah.txt is in your current directory. Otherwise you'll have to include the full path for the file.

  5. #5
    Registered User
    Join Date
    Aug 2001
    Posts
    9
    cheers Zen that work perfectly
    yet another question how can i make cin.getline to terminate when the user presses enter with out haveing to make them type the ternial_char first.

    cheers

  6. #6
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    The default behavior of getline is to terminate when a newline is entered. I'm not sure what you mean by ternial_char, but is quite easy with i/o to leave characters in the buffer that affect how getline works. Post the code.

  7. #7
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Ooops my bad. I neglected to say that remove() is a regular c function. I'll be more specific next time.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with loading files into rich text box
    By blueparukia in forum C# Programming
    Replies: 3
    Last Post: 10-19-2007, 12:59 AM
  2. added start menu crashes game
    By avgprogamerjoe in forum Game Programming
    Replies: 6
    Last Post: 08-29-2007, 01:30 PM
  3. fopen vs. _open (for BIG image files)
    By reversaflex in forum C Programming
    Replies: 3
    Last Post: 04-01-2007, 12:52 AM
  4. Permanently deleting files
    By Yasir_Malik in forum Windows Programming
    Replies: 1
    Last Post: 08-01-2006, 10:07 PM
  5. deleting files not in fstream?
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 10-09-2001, 01:36 PM