Unable to use remove() on string?

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
use clear()
you can easily find the answer for such question by a little search
http://www.cplusplus.com/reference/string/string/
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
closed account (S6k9GNh0)
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
std::string filename = "...";
int result = remove(filename.c_str());

Remove takes a C string (char*), not a C++ string.
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
Topic archived. No new replies allowed.