int  remove ( const char * filename );

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).


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:

  Defined in ANSI-C.


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

main ()
  if( remove( "myfile.txt" ) == -1 )
    perror( "Error deleting file" );
    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.

© The C++ Resources Network, 2000