-
Removing a file
I created a program to encrypt/decrypt files. The problem is, it creates a new file for the encryption program.
Now I want to remove the unencrypted file.
I tried:
Code:
std::remove(d.filename);
But it doesn't work. Is there a way to remove a file when you're using a variable as the filename?
-
yes...
but your sample has missing parts - so it is hard to decide what is your problem
1. what type is d.filename? if it is std::string you probably need c_str() to pass const char* to remove
2. have you closed the file before trying to remove it?
-
unlink()? (edit: Ah, or remove() Was looking in the wrong section...)
And note that on most computers, removing a file just removes the links to the data - the actual data itself is not cleared until something else overwrites it.
-
Thanks vart. I got it to work:
Code:
source.close();
std::remove(d.filename.c_str());