“删除文件时出错:权限被拒绝”用C ++删除 [英] "Error deleting file: Permission denied" with remove in C++
问题描述
当我编译并运行我的C ++程序,删除一个名为example.txt的文件时(下面)
#include< stdio.h中>
$ b $ int main()
{
if(remove(example.txt)!= 0)
perror(错误删除文件);
else
puts(File successfully deleted);
返回0;
$ / code $
cd c:\ Users \Mark\Desktop
C:\ Users \Mark\Desktop> app.exe
删除文件时出错:Permission denied
我解除了对文件的所有限制, (这应该包括我的程序)。
任何解决方案?
编辑
当我在命令提示符下键入 del example.txt
时,它可以正常工作。
奇怪...
解决方案我猜是 std :: remove()
将路径作为参数。所以我们需要指定整个路径作为 remove
函数的参数。
例如: remove(home / xxx / example.txt);
When I compile and run my C++ program that deletes a file called example.txt (below)
#include <stdio.h>
int main ()
{
if( remove( "example.txt" ) != 0 )
perror( "Error deleting file" );
else
puts( "File successfully deleted" );
return 0;
}
It comes out like this...
cd c:\Users\Mark\Desktop
C:\Users\Mark\Desktop>app.exe
Error deleting file: Permission denied
I lifted all restrictions on the file and there is full access to anyone (that should include my program).
Any solutions?
EDIT
When I type in del example.txt
on command prompt it works.
Weird...
解决方案 I guess std::remove()
takes the path as a parameter. So we need to specify the entire path as a parameter for remove
function.
eg: remove("home/xxx/example.txt");
这篇关于“删除文件时出错:权限被拒绝”用C ++删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!