Sign in to follow this  
bluefox25

Pausing Prompt screen

Recommended Posts

bluefox25    100
How do I pause the command prompt from closing while compiling and running my programs? The book I have says to use system("pause") is this safe? Is there a way to add this type of statement as a template so that I don't have to write it every time? I use Dev C++, thinking about going to VSC++ 2008, I use to use 2005 edition, is VS C++ 2008 better than 05?

Share this post


Link to post
Share on other sites
NathanRunge    725
Using the system pause is quite safe, and it's the standard thing to stick in there if you want to pause at a certain point for checking, or to give the user time to read something. Alternatively, you could simply stick in a 'cin' if all you need is to pause so you can check it works properly.

Share this post


Link to post
Share on other sites
gekko    478
The command prompt closes because the application which launched it (your program), has ended. If you, the user, open the command prompt and then launch the program, it didn't open the command prompt, and therefore won't close it on you.

Simply open the command prompt (Start->run cmd), navigate to the folder with your program in it, and run it. It'll stay open once it has finished.

Better yet, install the "Command Prompt Here" function to your context menu in Windows. Vista has it by default (Hold Shift, then right click on a folder) and Windows has it as part of some package Microsoft offered (Powertoys, maybe). It'll open the command prompt exactly where you need it.

EDIT: Powertoys for XP was correct.
http://www.microsoft.com/windowsxp/downloads/powertoys/xppowertoys.mspx

Share this post


Link to post
Share on other sites
GuyWithBeard    1892
Also, if you move to Visual C++, starting the program without debugging (Ctrl + F5) keeps the console open until you press a key after the program has finished. Needless to say, this only works if you don't want to debug your program, but I find it nice at times when I have a small program that just outputs a value I need.

Share this post


Link to post
Share on other sites
Daaark    3553
cin or system("pause") will both suit you fine. Why do these things always turn into long drawn out things?

08 is better than 05 in that it includes easier support for compiling Windows apps out of the box. You have to hack around the config files to get the platform SDK to work with 05. With 08 I don't even think you need the platform SDK just for a simple window app.

Share this post


Link to post
Share on other sites
jouley    805
Quote:
Using the system pause is quite safe...

Unless you're trying to write portable code that doesn't waste time. (Which you should be, especially since it's not that hard in this case.) Learning to use the command line is imperative for any serious programmer, not too difficult to learn, and, at times, more useful than double-clicking your way around.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this