上课老师问这么个问题,怎么在程序中删除一个文件。上网查了个方法。
用remove函数
功 能: 删除一个文件
用 法: int remove( const char *filename);
头文件:在Visual C++ 6.0中可以用stdio.h
返回值:如果删除成功,remove返回0,否则返回EOF(-1)。
例:
1 #include <stdio.h>
2
3 int main()
4 {
5 if(remove("1.txt"))
6 printf("Could not delete the file &s \n","1.txt");
7 else printf("OK \n");
8 return 0;
9 }
2
3 int main()
4 {
5 if(remove("1.txt"))
6 printf("Could not delete the file &s \n","1.txt");
7 else printf("OK \n");
8 return 0;
9 }
1.txt在程序目录下