[try Beta version]
Not logged in

 
Unable to use remove() on string?

Apr 22, 2009 at 7:46am
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
Apr 22, 2009 at 8:21am
use clear()
you can easily find the answer for such question by a little search
http://www.cplusplus.com/reference/string/string/
Apr 22, 2009 at 8:55am
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
Apr 22, 2009 at 12:01pm
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 Apr 22, 2009 at 1:33pm
Apr 22, 2009 at 1:13pm
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
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
Topic archived. No new replies allowed.