I'm using remove(inputPath.c_str()); to remove a file after a while loop is completed, but the file remains. I'm using Vista and logged in as an administrator and the file is located in my home folder. Any help would be appreciated. Thanks in advance.

#include <cstdlib>
#include <iostream> 
#include <fstream>
#include <stdio.h>

using namespace std;

int main(int argc, char *argv[]){
    
    cout << "Input Path: ";
    string inputPath = "";
    getline(cin, inputPath);
    ifstream plainText(inputPath.c_str());
    cout << '\n';
    
    cout << "Output Path: ";    
    string outputPath= "";
    getline(cin, outputPath);
    ofstream cipherText(outputPath.c_str());
    cout << '\n';
    
    cout << "Shift Value = ";
    int shiftValue = 0;
    cin >> shiftValue;
    cout << '\n';
    
    while (!plainText.eof()){
    
        string plainLine = "";
        getline(plainText, plainLine);
        
        int lineLength = 0;
        lineLength = plainLine.length();  
        
        for (int i=0; i<=lineLength; i++){
            
            int decimalValue[lineLength];
            char cipherLine[lineLength];
        
            decimalValue[i] = (int)plainLine[i] + shiftValue; 
            cipherLine[i] = (char)decimalValue[i];
            cipherText << cipherLine[i];  
            }   
  
        cipherText << '\n';
        }
  
    remove(inputPath.c_str());
  
    system("PAUSE");
    return EXIT_SUCCESS;
    }

Of course it can't be deleted because the program has it open. You have to close the file before attempting to delete it.

[edit]And what ^^^ said too.

Edited 7 Years Ago by Ancient Dragon: n/a

Ahh, how could I be so unconscientious? Thank you very much guys!

This question has already been answered. Start a new discussion instead.