[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 215
  • Last Modified:

How to 'deletel a file w/ g++

How do I delete this file

I don't want to end up with an 0byte file
here is what i have now
#include <fstream.h>
int main()
{fstream tmpfile;
 tmpfile.open(RunName,ios::in|ios::out);
 tmpfile.deletedammit!();
 tmpfile.Please?();
}
0
Rusk
Asked:
Rusk
  • 2
  • 2
1 Solution
 
nietodCommented:
Standard C++ does not provide and mechanism for deleting files because standard C++ is OS independant and any such mechanism would be OS dependant (because some OS's support directories, some don't, some support 8.3 file names, some support longer ones, some support security etc.).  

 However al operating systems will provide a mechanism to do this.  What operating system are you running on?
0
 
RuskAuthor Commented:
I'm running on Unix do you have any idea on how to do this on unix?
0
 
RuskAuthor Commented:
for other readers:

#include <stdio.h>
#include <fstream.h>

int main()
{fstream tmpfile;
 tmpfile.open(RunName,ios::in|ios::out);
 Remove(RunName);
}
works fine

0
 
nietodCommented:
Remove() is probably a procedure from the run-time library you are using.  This is a non-standard procedure, so it will (probably) not be supported by all compilers on UNIX.   I believe the OS command to delete a file in UNIX is called unlink().  That should be supported by all compilers on UNIX.  You can use either, but just be aware that remove() may not be available if you change compilers.   And neither will be available if you change platforms.  (If there is any chance of either of these events, then you should consider writting your own delete procedure, that calls upon remove() or unlink().  Then use this procedure throughout your code.  Then if you change compilers/platforms, you just need to change the code inside this procedure, you don't need to change the code anywhere else in the program.
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now