*Deleting* Files Using C++
-
Hi. I have a question about deleting a few. Here is a scenario. The program first asks the user to enter the name of a file to take to. ostream outFile; outFile.open(userchoice, ios::out); With ofstream, I found that it will create the file if it cannot find it. I tried implementing "nocreate," but VC++ 6 gave me an error that there is not such function "ios::nocreate." Anyways, the program would create the file if it cannot find it and the file would be empty or 0 byte size. Afterward, the program calculates specific data (not worth mentioning) and outputs data to the outpuf *if applicatable*. So sometimes the program writes nothing and I would a 0 byte file under the name that the user originally entered. I would like to know if there is a way to delete a file. So in the case above, there would be a line of code to delete the file if applicable. Thanks, Kuphryn
-
Hi. I have a question about deleting a few. Here is a scenario. The program first asks the user to enter the name of a file to take to. ostream outFile; outFile.open(userchoice, ios::out); With ofstream, I found that it will create the file if it cannot find it. I tried implementing "nocreate," but VC++ 6 gave me an error that there is not such function "ios::nocreate." Anyways, the program would create the file if it cannot find it and the file would be empty or 0 byte size. Afterward, the program calculates specific data (not worth mentioning) and outputs data to the outpuf *if applicatable*. So sometimes the program writes nothing and I would a 0 byte file under the name that the user originally entered. I would like to know if there is a way to delete a file. So in the case above, there would be a line of code to delete the file if applicable. Thanks, Kuphryn
-
Thanks. ofstream x; x.open(file, ios::out); s.remove(file); // Is this a valid syntax? Kuphryn
-
Hi. I have a question about deleting a few. Here is a scenario. The program first asks the user to enter the name of a file to take to. ostream outFile; outFile.open(userchoice, ios::out); With ofstream, I found that it will create the file if it cannot find it. I tried implementing "nocreate," but VC++ 6 gave me an error that there is not such function "ios::nocreate." Anyways, the program would create the file if it cannot find it and the file would be empty or 0 byte size. Afterward, the program calculates specific data (not worth mentioning) and outputs data to the outpuf *if applicatable*. So sometimes the program writes nothing and I would a 0 byte file under the name that the user originally entered. I would like to know if there is a way to delete a file. So in the case above, there would be a line of code to delete the file if applicable. Thanks, Kuphryn
remove("file") works well. There is one weird issue. the remove() function works even when I do not include "cstdio." This is also true for a few other functions. Why? Note I do not use "namespace std." Is VC++ compiler including some libraries automatically? Kuphryn
-
remove("file") works well. There is one weird issue. the remove() function works even when I do not include "cstdio." This is also true for a few other functions. Why? Note I do not use "namespace std." Is VC++ compiler including some libraries automatically? Kuphryn
remove() is a C function prototyped in stdio.h or io.h. You can also use _unlink(). /ravi "There is always one more bug..." ravib@ravib.com http://www.ravib.com