0

I am developing a very simple notepad-type program in C++. The only problem is that when I prompt the user to delete their newly written text file, it doesn't work. Since I let the user pick the name for his/her file, I can't figure out the code to delete it. IT'S VERY URGENT. PLEASE HELP!!!

If (fSave == "n")
[
//How do I delete a file with a string name???
]

P.S.
To let the user choose the file name, I did
myfile.open (fname.c_str());

3
Contributors
5
Replies
6
Views
5 Years
Discussion Span
Last Post by i3-540
0

Post your code, it will help us to identify your problem and answer is correctly.

P.S

You can always use remove() method to delete a file.

And if its a windows API then

BOOL DeleteFile(

LPCTSTR lpFileName   // pointer to file name

);
0

Could you please show me how to do the remove() function with a string fname?

0

First dont forget to close it
myfile.close()
if im not mistaken.

and then as np complete said
using the remove function posted in the msg

0

well since Remove() needs to get a char
just using the fname.c_str() should do the trick
remove(fname.c_str());

keep us posted

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.