Sep 13, 2015 at 6:19pm UTC
Hello
I'm trying to delete a simple Text-file, the function returns 1 (successful) but when I look in the Windows File Explorer, the file is still there.
What to do?
1 2 3 4 5 6 7 8 9 10 11 12 13 14
int deleteFile(string fileToDelete) {
char *cstr = new char [fileToDelete.length()];
strcpy_s(cstr, 256, fileToDelete.c_str());
ifstream fileExistance(cstr);
if (fileExistance) {
if (remove(cstr)) {
return 1;
} else {
return 0;
}
} else return 3;
}
Thanks for reading,
Niely
Last edited on Sep 13, 2015 at 6:19pm UTC
Sep 13, 2015 at 6:31pm UTC
1) remove , like many other C functions, returns 0 (false) on success.
2) You cannot delete open file, and in your codeyou are trying to do exactly that.
Sep 13, 2015 at 6:42pm UTC
^Thanks a lot!
Your first response helped me a lot! ;D
Sep 13, 2015 at 6:48pm UTC
I still have another problem, when I run my application, I sometimes get a Breakpoint error.
What is it, and how to resolve it?