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

This is a discussion on std::remove("File1.txt"); within the C++ Programming forums, part of the General Programming Boards category; I am trying to remove a file named File1 like this but this doesn´t remove(delete) this file. I beleive it ...

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

    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 03:27 PM.

  2. #2
    Registered User
    Join Date
    Dec 2007
    Posts
    383
    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,893
    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

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