C++ “权限被拒绝”“Id 返回 1 个退出状态”是什么意思?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18667502/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 22:06:45  来源:igfitidea点击:

What does "Permission denied" "Id returned 1 exit status" mean?

c++c

提问by user2755844

I am taking a class on C, and I'm not very good at it , so I would like to ask you, how do I solve the problem: "Id returned 1 exit status", I have been struggling with it for quite a while, so I would really appreciate your help.

我正在上C课,我不太擅长,所以我想问你,我如何解决这个问题:“Id返回了1个退出状态”,我一直在为此苦苦挣扎同时,所以我真的很感激你的帮助。

#include <stdio.h>
#include<conio.h>
#include<windows.h>
int main()
{
  int P, N, NP=0;
  printf("Introduzca en nombre del producto:\n");
    scanf("%f", &N);
  printf("Introduzca en precio del producto:\n");
    scanf("%f", &P);
  if (P <= 1500)
        NP=P*1.11;
  else 
        NP=P*1.08;
   printf("El producto %d cuesta %d", NP, N);
   getche();
   return 0;
}

The full list of errors is:

完整的错误列表是:

Permission denied

Id returned 1 exit status

回答by pampeho

It does not have anything to do with code. Your operating system simply does not allow to modify a file while it is in use, so the compilation (actually, linking, ldis the linker) fails, because compiler can't remove the old executable and place a new one. To solve this, simply close all existing processes running that program.

它与代码没有任何关系。您的操作系统根本不允许在使用文件时对其进行修改,因此编译(实际上,链接,ld是链接器)失败,因为编译器无法删除旧的可执行文件并放置一个新的可执行文件。要解决这个问题,只需关闭所有运行该程序的现有进程。

If that won't work, check your permissions for directory the executable is in, or look for any programs that are currently using it (some systems allow programs to place a lock on a file, so no other program can modify it).

如果这不起作用,请检查可执行文件所在目录的权限,或查找当前正在使用它的任何程序(某些系统允许程序锁定文件,因此其他程序无法修改它)。

回答by Greg Hewgill

There's something wrong here:

这里有问题:

int N;
scanf("%f", &N);

Your data types do not match.

您的数据类型不匹配。

回答by Sonadore

I know the problem is already well solved, but I want to offer another perspective for those who are haunted by the bug message

我知道问题已经很好地解决了,但我想为那些被错误消息困扰的人提供另一个视角

"[Error] Id returned 1 exit status"

“[错误] ID 返回 1 个退出状态”

So here it is:

所以这里是:

If you compile a C/C++ source file with no main function to execute, there will definitely be a bug message saying:

如果你编译一个没有执行 main 函数的 C/C++ 源文件,肯定会有一个错误信息说:

"[Error] Id returned 1 exit status"

“[错误] ID 返回 1 个退出状态”

But sometimes we just don't need main function in the file, in such a case, just ignore the bug message.

但有时我们只是不需要文件中的 main 函数,在这种情况下,只需忽略错误消息。

回答by SpikeTheBear

This happened to me when i accidently marked my .exe file read only. When i removed it it worked again. (IDK much about programming but this happened to me mayb it helps someone)

当我不小心将我的 .exe 文件标记为只读时,这发生在我身上。当我删除它时,它又工作了。(IDK 很多关于编程,但这发生在我身上,可能对某人有帮助)

回答by Agu Nunes

if you are compiling in the terminal you need:

如果您在终端中编译,您需要:

su
gcc file.c -o nameyouwant
./nameyouwant

回答by some user

I'd like to add something to papeho'sanswer:

我想在papeho 的回答中添加一些内容

If you are using any antivirus software, this may be the reason. Some antivirus might be the fact here, probably for including stdio.h,windows.hor conio.hit predicts that working with such headers may causes attacks on your PC

如果您正在使用任何防病毒软件,这可能是原因。某些防病毒软件可能是事实,可能包括stdio.hwindows.h或者conio.h它预测使用此类标头可能会导致对您的 PC 的攻击

Probable ways to get rid of it:

摆脱它的可能方法:

1.Try to delete the existing executable file. (Failed because it's being locked on something (maybe antivirus) )

1.尝试删除现有的可执行文件。(失败,因为它被锁定在某些东西上(可能是防病毒软件))

2.Simply rename that file, then rebuild and done (renaming will allow to create another executable file for your code).

2. 只需重命名该文件,然后重建并完成(重命名将允许为您的代码创建另一个可执行文件)。

3.If failed restarting pc and trying from 1 may fix this. Hope it helps :-)

3.如果重启电脑失败并从1开始尝试可能会解决这个问题。希望能帮助到你 :-)

回答by RafaelFigueiredo

I was having the same error. And it was a bit difficult to solve because the message says that don't have permission to open the file. But the problem is that the program is still running.

我有同样的错误。而且解决起来有点困难,因为消息说没有打开文件的权限。但问题是程序仍在运行。

If the program is still running I thought that I will find inside task manager, but wasn't there. So, I tried to delete the file and I wasn't able to delete too. Searching more about I find the program "Process Explorer". With this program I was able to see that my exe file is still running, but with a message saying that the program was suspended. Then I tried to kill through Process Explorer, but without success, because I still don't have permissions. So I close Process Explorer and open with administrator permissions and after all this I was able to kill the process and build and run my file through codeblocks.

如果程序仍在运行,我以为我会在任务管理器中找到,但不在那里。所以,我试图删除该文件,但我也无法删除。搜索更多关于我找到程序“进程资源管理器”。使用这个程序,我能够看到我的 exe 文件仍在运行,但有一条消息说该程序已暂停。然后我尝试通过 Process Explorer 杀死,但没有成功,因为我仍然没有权限。所以我关闭了进程资源管理器并以管理员权限打开,毕竟我能够终止进程并通过代码块构建和运行我的文件。

回答by Tommy Au

I think you should simply change int NP=0;to: float NP=0;

我认为你应该简单地int NP=0;改为:float NP=0;

Also change: scanf("%f",&N);and: scanf("%f",&P);to: scanf("%d"&N);and scanf("%d"&P);

同时将: scanf("%f",&N);and: scanf("%f",&P);改为: scanf("%d"&N);andscanf("%d"&P);

And:getche();to: getch();

并且:getche();到:getch();

I hope this can help you.

我希望这可以帮助你。

回答by Konstantin Nosachov

Alt+F2 in your ide... its sometimes realy helps when you forgeting to close "run" window hah)

在您的 ide 中使用 Alt+F2 ......当您忘记关闭“运行”窗口时,它有时真的很有帮助哈)

回答by Ali Albar

#include <iostream>
#include <conio.h>
#include <string.h>

using namespace std;
void gotoxy(short x, short y);
int main()
{
     FILE *ptrFile= fopen("E:\ENCD_OUTPUT.html","a");
     char a[30];
     cin >> a;
     cout << a;
     gotoxy(14, 4);
     fputs(a, ptrFile);
     gotoxy(13, 6);
     fputs(a, ptrFile);
     getche();
}