Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 My exe file automatically closes
Index -> Programming, C++ -> C++ Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Cancer Sol




PostPosted: 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
Sponsor
sponsor
ishidon




PostPosted: 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




PostPosted: 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.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Zren




PostPosted: 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




PostPosted: Fri Mar 08, 2013 7:44 pm   Post subject: Re: My exe file automatically closes

@ishidon Yup, I found out about it Razz
@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




PostPosted: 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




PostPosted: 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 Razz
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! Smile
Display posts from previous:   
   Index -> Programming, C++ -> C++ Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 7 Posts ]
Jump to:   


Style:  
Search: