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());

Recommended Answers

All 5 Replies

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

);

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

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

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

Thank you so much for the help :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.