I've created, and written to a file. It lets me do all of that just fine, but when I try to delete the file it says that I do not have permission. Is there something wrong with my code?:
#include <cstdlib>
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
char fileName[80] = "C:\\main.cpp";
ofstream fout(fileName, ios::app);
fout << "At the end\n";
fout.close();
ifstream fin(fileName);
char ch;
while(fin.get(ch))
{
cout << ch;
}
if (remove(fileName) == -1)
{
perror("Error deleting file: ");
}
else
{
cout << "Successful";
}
system("PAUSE");
return(0);
}
I have checked to make sure the file isn't read only, which it's not.