Thread: std::remove("File1.txt");

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    385

    std::remove("File1.txt");

    I am trying to remove a file named File1 like this but this doesn´t remove(delete) this file.
    I beleive it is the correct syntax to delete a file.


    Code:
    #include "stdafx.h"
    #include <iostream>
    #include <fstream>
    #include <sstream> 
    #include <string>  
    
    
    using namespace std;
    
    int main()
    {
       ifstream input  ("File1.txt");
       ofstream output ("File2.txt");
       
          {
             output << "Text" << "\n";
          }
    	  std::remove("File1.txt");
    
       return 0;
    }
    Last edited by Coding; 02-19-2008 at 04:27 PM.

  2. #2
    Registered User
    Join Date
    Dec 2007
    Posts
    385
    I just found it out. I forgot to close the file with

    Code:
    input.close();

  3. #3
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    And remove() is part of <cstdlib>. Or <cstdio>. Look it up.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    stdio

Popular pages Recent additions subscribe to a feed