Jump to content
  • Advertisement
Sign in to follow this  
Winegums

Console window termination

This topic is 4171 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've started learning C# and i have that old problem of the console window closing the minute it hits the end of the app (no 'press any key to continue' style prompt). it's been an age since i've had this problem in C++ and i can't recall how to fix it, is there a project setting i have to change? I know i could hash it a bit (no pun intended) and just put some sort of scanf() type function in at the end, but i'd rather not if it were avoidable.

Share this post


Link to post
Share on other sites
Advertisement
there's nothing specific to do , it's what it's supposed to do it's done it terminates , if you want to have time to see the output without changing your program you could launch your program from a command pront wich will remain active & waiting on your input after program termination (in c++ some compilers offered option to wait on end but it's compiler specific)

Share this post


Link to post
Share on other sites
A simple way would be to ask the application to wait for an input

Console.ReadLine()


The the system will wait for an input and striking enter will causes the apllication to continue and then close

Share this post


Link to post
Share on other sites
If you're using Visual C# you should be able to use the 'Start Without Debugging' (Ctrl+F5) from the Debug menu. Alternatively, running you application from the console as suggested by ranakor will avoid the problem. You may or may not also be able to prevent the window from closing by setting a breakpoint at the end, but I'm not sure about that one.

TigerSam: That will work, but it's technically an abuse of whatever functionality you use to do so. It's correct behavior for a console application to run and then close.

Share this post


Link to post
Share on other sites
ok thanks for the replies. i had been using Console.Read(), but it wasn't working because i was pushing space bar (perhaps the only key that doesn't make the program just bail).

I know it's not tidy practice, but if it's only for test programs then it's not too bad...

Share this post


Link to post
Share on other sites
You could use: system("pause");

which just stops your programs execution until a key is pressed.

The Dev-C++ editor uses this as a default, so im used to using it other environments.

Share this post


Link to post
Share on other sites
Quote:
Original post by cresty
You could use: system("pause");

which just stops your programs execution until a key is pressed.

The Dev-C++ editor uses this as a default, so im used to using it other environments.


I use Dev-C++ as well and at first I could not get it to pause but then one day it worked. I had the cstdio directive as well. I use it now even on VSC+.

Will Dev-C++ work on Linux?

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!