+ 1
return 0 not working in exe
Im using the regular g++ to compile my code. I'm just wondering cause with g++ and even codeblocks, return 0 is working fine. except when I double click the exact .exe file that i compiled. Where it will just closed right after I enter an input on the code. I have a simple input program in here where the user can input a number to set age. it works fine with the g++ cmd console and codeblocks. but not when I double click the exe file.
4 Respuestas
+ 1
Thanks for the link. yah all of those, I've already done. it worrks fine with g++ and other IDE. but my problem is when Im running the .exe file that is sitting on the folder im working on. well as im wondering maybe this is not really going to work with a straight linear program like hello world, for most of the programs are running loop, where in one function is waiting an input for you to exit the application. correct me if im wrong. Thats just what i think happening ;)
0
The purpose of return 0 at the end of main() is to verify that the program executed without errors. If a non-zero value is returned by main() then the program is flawed. When debugging, Codeblocks waits for the user to enter a key before terminating the program. Notice that this is not related to return 0. When running the app from the cmd, the program will immediately terminate when return 0 is reached in main(). If you are sing Windows, you could add System("pause"); just before return 0. Though a more portable solution might be to add getchar(); just before return 0.
0
@NNNicomedes thanks for answering. I already did try using systempause and get char. but i think this 2 line off code only works with visual studio. whever i compile it with just g++ it will give me an error saying system was not declared.