c++ remove函数

jackxiang 2008-3-17 11:40 | |
remove function
int remove ( const char * filename ); <cstdio>

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
/* 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 example.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
rename Rename file (function)

作者:jackxiang@向东博客 专注WEB应用 构架之美 --- 构架之美,在于尽态极妍 | 应用之美,在于药到病除
地址:https://jackxiang.com/post/947/
版权所有。转载时必须以链接形式注明作者和原始出处及本声明!

评论列表
发表评论

昵称

网址

电邮

打开HTML 打开UBB 打开表情 隐藏 记住我 [登入] [注册]