Apr 22, 2009 at 7:46am UTC
I have been trying to use remove() on a file name that is stored in a string variable with no success.
Is there any other way to do so?
Last edited on Apr 22, 2009 at 7:46am UTC
Apr 22, 2009 at 8:55am UTC
you can easily find the answer for such question by a little search
I guess I wasn't clear enough(pun intended). Let me elaborate.
I want to delete a file. The file name consists of 3 parts, namely:
1) A value from an ini file.
2) A date.
3) The extension ".txt".
Eg. Name090422.txt
How do I delete this file?
Last edited on Apr 22, 2009 at 10:43am UTC
Apr 22, 2009 at 12:01pm UTC
You could call a system command which I wouldn't recommend.
OR
int remove(const char * filename);
1 2
remove("C:/deleteme.txt" ); //should work. Notice the slash is different.
//I've heard of remove( "C:\\Deleteme.txt" ); format as well.
Last edited on Apr 22, 2009 at 1:33pm UTC
Apr 22, 2009 at 1:13pm UTC
std::string filename = "...";
int result = remove(filename.c_str());
Remove takes a C string (char*), not a C++ string.
Apr 23, 2009 at 12:54am UTC
1 2
std::string filename = "..." ;
int result = remove(filename.c_str());
Thank you! I'm a newbie at C++ and this is exactly what I wanted.
Thanks again.
Last edited on Apr 23, 2009 at 12:54am UTC