你好,我的問題是爲什麼下面的函數無法刪除名稱在dir1中指定的文件; 我使用刪除功能,但它似乎有某種問題。 請幫幫我。使用函數從stdio.h中刪除(..)的問題C++
#include <stdio.h>
void test(char* dir1,char* dir2)
{
FILE * file1,* file2;
file1=fopen(dir1,"r");
file2=fopen(dir2,"w");
if(!file1){ return;}
int inpch;
char* string = new char[10];
string[9]='\0';
int br=0;
do
{
while((inpch=fgetc(file1))!=EOF)
{
string[br]=char(inpch);
br++;
if(br==9)break;
}
if(br!=9)
{
string[br]='\0';
fputs(string,file2);
return;
}
else
{
fputs(string,file2);
br=0;
}
}while(true);
fclose(file1);
remove(dir1);/// I DON"T UNDERSTAND WHY IT DOESN"T DELETE THE FILE.
fclose(file2);
}
你(而不是程序)是否有適當的權限來刪除文件? – 2011-06-10 17:27:52
@Michael:'unlink'有14個錯誤情況,''remove'正在調用'rmdir'系統調用13個。我們是否會在一個或另一個案例中詢問OP 17次的確切性? :) – 2011-06-10 17:30:04
@Vlad:不。只有一個。 :) – 2011-06-10 17:44:08