remove
int  remove ( const char * filename );
stdio.h
  cplusplus.com  

Delete a file.
  Deletes the file specified by filename. It is compiled as a call to the system function for deleting files (unlink, erase or del).

Parameters.

filename
Path and name of the file to be removed.

Return Value.
  If the file is succesfully deleted a 0 value is returned.
  On error a non-zero value is returned and the errno variable is set with the corresponding error code that that can be printed with a call to perror:

Portability.
  Defined in ANSI-C.

Example.

/* remove example: remove myfile.txt */
#include <stdio.h>

main ()
{
  if( remove( "myfile.txt" ) == -1 )
    perror( "Error deleting file" );
  else
    puts( "File successfully deleted" );
  return 0;
}
  If the file example.txt existed before the execution and we had write access to it the file will be deleted and this message will be written to stdout:
File successfully deleted
Otherwise, a message similar to this will be written to stderr:
Error deleting file: No such file or directory

See also.
  rename


© The C++ Resources Network, 2000