I'm using the c++ remove() function but it will not delete the file for some reason =(
Ideas?
I'm using the c++ remove() function but it will not delete the file for some reason =(
Ideas?
"Anyone can aspire to greatness if they try hard enough."
- Me
Could it be some kind of permission problem? Perhaps you could post the smallest and simplest compilable code that demonstrates the problem.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Okay... im actually having another problem coupled with this but i'll post that one seperately.
Code:void deleteSnakeFile(string file) { string rem= "/snakes/"+file+".dea"; remove(rem.c_str()); //remove from list vector<string> rnames; vector<string> rums; loadSnakeList(rums, rnames); //Search int pos; for(int i=0; i < rums.size(); i++) { if(rums.at(i) == file) { pos = i; } } //Rewrite file ofstream fout2("snakes/main_list.txt"); for(int i=0; i<rums.size(); i++) { if(i != pos) { fout2<<rums.at(i)<<"-"<<rnames.at(i)<<"\n"; } } fout2.close(); //Done }
"Anyone can aspire to greatness if they try hard enough."
- Me
Are you sure the current directory is correct? It isn't always the same as your executable directory, so when you use relative paths they are sometimes not what you expect. Test it with the full path and see if that works.
If the path is right, be sure that any fstreams that you have used with that file have been closed.
Last edited by Daved; 07-12-2007 at 11:35 PM.
One path is absolute, and the other is relative ?
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Expanding on Salem's idea, I would guess that you meant to use a relative path here, like you did lower down:
->Code:string rem= "/snakes/"+file+".dea";
Unless you've created a folder on the root of your drive, c:\snakes, for example. In which case it'd be the other way around.Code:string rem= "snakes/"+file+".dea";
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.