Deleting a file while in a program

This is a discussion on Deleting a file while in a program within the C++ Programming forums, part of the General Programming Boards category; Ahm Baahk! Any way, i want to write a program the deletes a file, but i dont know how to ...

  1. #1
    Linux Forever
    Join Date
    Oct 2002
    Posts
    373

    Deleting a file while in a program

    Ahm Baahk! Any way, i want to write a program the deletes a file, but i dont know how to do that. Any help? Thanks in advance!
    This war, like the next war, is a war to end war.

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    One way is remove().
    Code:
    #include <iostream>
    #include <cstdio>
    
    using namespace std;
    
    int main(void)
    {
       char *filename = "\\dir\\file.txt";
    
       if (remove(filename) == 0)
          cout << "File has been deleted" << endl;
       else
          cout << "Unable to delete file." << endl;
       return 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A development process
    By Noir in forum C Programming
    Replies: 37
    Last Post: 07-10-2011, 11:39 PM
  2. Basic text file encoder
    By Abda92 in forum C Programming
    Replies: 15
    Last Post: 05-22-2007, 02:19 PM
  3. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 05:54 PM
  4. Encryption program
    By zeiffelz in forum C Programming
    Replies: 1
    Last Post: 06-15-2005, 04:39 AM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 11:04 PM

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