Jump to content
  • Advertisement
Sign in to follow this  
Rayben

console question

This topic is 4236 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi! I'm experimenting with c++ and concole applications in windows XP with visual c++ express. My question is: is there a way of preventing the console application from shutting down instantly after the main function is ended? My temporary solution is to add char x; cin >>x; just before the end of main to stall it untill I enter a character. However, I'm experimenting with destructors that display a text when they are called and if it is a globaly declared object then my little trick wont work because the call to the destructor is made after main() ends. Thanks for any help, /Rayben

Share this post


Link to post
Share on other sites
Advertisement
there's always the system("pause") which launces a thread to wait for a keystroke from the user.
of course, it's not the best use.

you can implement a Sleep() before actually hitting the return() in main, for example.

Share this post


Link to post
Share on other sites
In your case, either avoid using global objects, or use a .bat file to run your program and pause the console screen after it's run:

programname
pause

or wait for users input in those destructors. Not recommended, but hey, you're experimenting. Bytheway, using getchar() saves you a line of code. :)

Share this post


Link to post
Share on other sites
Thanks!

Never thaught of using batch files, they allways were a mystry to me.
I think I'll dig deeper into the workings of those strange things.

Share this post


Link to post
Share on other sites
The best way to handle this problem is to put a breakpoint at the very end of your program. Another solution is to run your program from the console (and not from the debugger).

I strongly advice you to stay awy from solutions that wait for a user input. I even urgely want you to avoid system("pause") (which is possibly the worst solution to the problem).

Regards,

Share this post


Link to post
Share on other sites
use ctrl + F5 instead of F5 or click Debug->Start Without Debugging (may require you to use a release build). Alternativly run it from the command line.

Edit: grr im to late oh well i was trying to find a link for you but couldnt.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!