Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
Miscellaneous
C Library
cassert (assert.h)
cctype (ctype.h)
cerrno (errno.h)
cfloat (float.h)
ciso646 (iso646.h)
climits (limits.h)
clocale (locale.h)
cmath (math.h)
csetjmp (setjmp.h)
csignal (signal.h)
cstdarg (stdarg.h)
cstddef (stddef.h)
cstdio (stdio.h)
cstdlib (stdlib.h)
cstring (string.h)
ctime (time.h)
cstdio (stdio.h)
functions:
clearerr
fclose
feof
ferror
fflush
fgetc
fgetpos
fgets
fopen
fprintf
fputc
fputs
fread
freopen
fscanf
fseek
fsetpos
ftell
fwrite
getc
getchar
gets
perror
printf
putc
putchar
puts
remove
rename
rewind
scanf
setbuf
setvbuf
sprintf
sscanf
tmpfile
tmpnam
ungetc
vfprintf
vprintf
vsprintf
macro constants:
EOF
FILENAME_MAX
NULL
TMP_MAX
objects:
stderr
stdin
stdout
types:
FILE
fpos_t
size_t


remove

function
<cstdio>
int remove ( const char * filename );

Remove file

Deletes the file whose name is specified in filename.
This is an operation performed directly on a file; No streams are involved in the operation.

Parameters

filename
C string containing the name of the file to be deleted. This paramenter must follow the file name specifications of the running environment and can include a path if the system supports it.

Return value

If the file is successfully deleted, a zero value is returned.
On failure, a nonzero value is reurned and the errno variable is set to the corresponding error code. Error codes are numerical values representing the type of failure occurred. A string interpreting this value can be printed to the standard error stream by a call to perror.

Example

1
2
3
4
5
6
7
8
9
10
11
/* remove example: remove myfile.txt */
#include <stdio.h>
int main ()
{
  if( remove( "myfile.txt" ) != 0 )
    perror( "Error deleting file" );
  else
    puts( "File successfully deleted" );
  return 0;
}


If the file myfile.txt existed before the execution and we had write access to it, then 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