My exe file automatically closes
Author |
Message |
Cancer Sol
|
Posted: Thu Mar 07, 2013 7:40 pm Post subject: My exe file automatically closes |
|
|
Hey guys, I'm just wondering... how do I have my exe to stay open after all the lines have been read? On Code::Blocks, when I compile and run it (I use GNU-GCC), it works fine. However, when I just click build and launch the exe from the folder, it still runs, but automatically closes after all lines have been read. There isn't any problems with the program though, it returned 0 for when I used the compile and run option on Code::Blocks (at least, that's what I think f9 does). |
|
|
|
|
|
Sponsor Sponsor
|
|
|
ishidon
|
Posted: Thu Mar 07, 2013 8:40 pm Post subject: Re: My exe file automatically closes |
|
|
Im guessing that you are just outputting values, so this means that your program will output the values and then close right after because the program is finished running. To get the program to pause just put a cin at the end, I don't know C++ but I think it should pause the program until you input something. |
|
|
|
|
|
Tony
|
Posted: Thu Mar 07, 2013 9:08 pm Post subject: RE:My exe file automatically closes |
|
|
In practice that's a bad idea, as you want a finished program to... well, finish.
Just execute the program from within the terminal window. Since you were the one to open that window, there will be a reason for it to stay open after the program is done. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
Zren
|
Posted: Thu Mar 07, 2013 9:22 pm Post subject: RE:My exe file automatically closes |
|
|
If Code::Blocks has a debugger, put a breakpoint on the last line of code (return). |
|
|
|
|
|
Cancer Sol
|
Posted: Fri Mar 08, 2013 7:44 pm Post subject: Re: My exe file automatically closes |
|
|
@ishidon Yup, I found out about it
@Tony I'm just trying to do that so that when my friend tries out a new program I made, it won't auto close. Now, I just use an if statement and see if the user wants to continue or not.
@Zren Code::Blocks Mingw (or whatever it is) includes a debugger, but what does that do? And do you mean I should put return at the end of my main function? |
|
|
|
|
|
Zren
|
Posted: Fri Mar 08, 2013 8:20 pm Post subject: Re: My exe file automatically closes |
|
|
Cancer Sol @ Fri Mar 08, 2013 7:44 pm wrote: @Zren Code::Blocks Mingw (or whatever it is) includes a debugger, but what does that do? And do you mean I should put return at the end of my main function?
A debugger allows you to stop the program at a certain point and look at the state of the variables.
If your code doesn't have a return; statement (returns nothing for a void function), add one. Then right click that line and select toggle breakpoint.
More info here: http://wiki.codeblocks.org/index.php?title=Debugging_with_Code::Blocks#Set_Breakpoints
It looks like you need to press f8 in order to run the program with the debugger. When it reaches the breakpoint, the code execution will freeze along with the output window hopefully still displayed. You can then continue (to the next breakpoint/end of the program) or cancel execution.
Quote: friend tries out a new program I made, it won't auto close
If that's the use case, then this method probably isn't the best. Though you should still try it as the debugger is a pretty powerful tool. |
|
|
|
|
|
Cancer Sol
|
Posted: Sat Mar 09, 2013 10:16 am Post subject: Re: My exe file automatically closes |
|
|
Hmm well that's really useful later on when I make more complicated codes
Thanks.
Actually, now I used an if statement to see if the user wants to continue or not (not sure if I mentioned it earlier) so this thread is solved I guess.
Again, thanks a lot everyone! |
|
|
|
|
|
|
|