Deleting a File by Name

This is a discussion on Deleting a File by Name within the C++ Programming forums, part of the General Programming Boards category; Hi, I have a program where I need the user to input the filename to be deleted. This is what ...

  1. #1
    Registered User BigSter's Avatar
    Join Date
    Nov 2001
    Posts
    47

    Cool Deleting a File by Name

    Hi,
    I have a program where I need the user to input the filename to be deleted.
    This is what I have so far:

    #include <iostream.h>
    #include <stdlib.h>
    #include <conio.h>
    #include <windows.h>
    #include <fstream.h>
    #include <string>

    using namespace std;
    string delfilename;

    int delfile()
    {
    system("CLS");

    cout<<"Enter File to be Deleted"<<endl;
    cin>>delfilename;
    system("del delfilename.c_str()"); // delete file
    system("PAUSE");
    }

    Thanks

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    I would recommend:

    remove(delfilename.c_str()); // delete file

    To use, #include <cstdio>
    Last edited by swoopy; 02-13-2002 at 01:48 AM.

  3. #3
    Registered User BigSter's Avatar
    Join Date
    Nov 2001
    Posts
    47
    Works perfect!
    Thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. To find the memory leaks without using any tools
    By asadullah in forum C Programming
    Replies: 2
    Last Post: 05-12-2008, 08:54 AM
  2. Need Help Fixing My C Program. Deals with File I/O
    By Matus in forum C Programming
    Replies: 7
    Last Post: 04-29-2008, 08:51 PM
  3. gcc link external library
    By spank in forum C Programming
    Replies: 6
    Last Post: 08-08-2007, 04:44 PM
  4. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 09:39 AM
  5. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 10:46 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21