开发者

netbeans does not run cpp application (even tho build is succesfull)

开发者 https://www.devze.com 2023-03-05 18:51 出处:网络
I am trying to run my first c++ program from the netbeans IDE, and apparently i am (?) but at the end i get an error message;

I am trying to run my first c++ program from the netbeans IDE, and apparently i am (?) but at the end i get an error message; Here is the code :

#include &l开发者_如何学Ct;iostream>

using namespace std;

void func(){
    for(int i =1;i<6;i++)
        cout<<endl<<"tony tests "<<i;
}
int main() {
    cout<<" p";
    func();
    return 1;
}

And here is the output ( right clicked the project then selected Properties ->Run->Console Type= Output Window not Default otherwise it will open a sh.exe window and my messages will be printed there)

p

tony tests 1

tony tests 2

tony tests 3

tony tests 4

tony tests 5

RUN FAILED (exit value 1, total time: 78ms)

So why do i get this error message, how can i correct the problem (even tho i doesn t interfere with the running of code + i can debug the code using from inside the ide ) and in what circumstances could the problem (that causes this error message appear) prevent my code from executing correctly or not execute at all? Also, what is exit value 1?


An exit value other than 0 indicates an error to the OS, so by returning 1 from main(), the OS believes that there has been an error in running your code, and therefore prints an error message at the end of the run. Changing the return value to 0 should solve the problem.

An exit value of 1 is considered a "general error" on most platforms. For instance, on POSIX, the error macro EXIT_FAILURE is equal to the value 1. The value passed to exit() or returned from main() should be between 0 and 255 ... anything greater can have unexpected or undefined results.

You can find more information on exit-status values here.


As Jason correctly pointed out, any operating system(all linux - not sure about windows though) will return a non zero no as an error and 0 as a success. There is specific error associated with each no. In C/C++ programming you can use errno.h and then you can print the the error generated like file not found or file pointer null or any error.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号