Sign in to follow this  
XandX2005

No brainer

Recommended Posts

So.... im trying to pick back up the reigns of C++ once again, and now im all confused AGAIN!!!! ahhhhhhh! When I compile a program it opens and closes almost simultaneously. I remeber having it so it didn't do that. What's goin on?

Share this post


Link to post
Share on other sites
Probably the easiest way to prevent that is running the program through your IDE (or atleast in Visual Studio, through Debug->Start without debugging). Or you can do it in the code itself with either system("PAUSE"), which seems to be frowned upon, or writing your own pause function (for instance, a while loop until a key is pressed).

Edit: The above assumes you are writing a console application.

Share this post


Link to post
Share on other sites
Quote:
Original post by MH6
Or you can do it in the code itself with either system("PAUSE"), which seems to be frowned upon


It's frowned upon because it unnecessarily limits your code to running only on Windows/DOS; other systems won't have a PAUSE command (all system() does is execute a command as though you had typed it at the command line).

Instead of double-clicking on your program, try running it from the command line, like command line programs are meant to be run; you'll have time to see your output then.

Share this post


Link to post
Share on other sites
Quote:
Original post by Captain_Thunder
Quote:
Original post by MH6
Or you can do it in the code itself with either system("PAUSE"), which seems to be frowned upon


It's frowned upon because it unnecessarily limits your code to running only on Windows/DOS; other systems won't have a PAUSE command (all system() does is execute a command as though you had typed it at the command line).

Instead of double-clicking on your program, try running it from the command line, like command line programs are meant to be run; you'll have time to see your output then.


Yep, but for temporary use it's more than adequate (Note the word temporary). Was also going to suggest the command line but I didn't know the OP's experience with such.

Share this post


Link to post
Share on other sites
You don't need any breakpoints or stuff like that. Simply execute the program from Visual Studio with ctrl+f5 instead of just F5. If you want to see the output when executing from outside the IDE, either run it from the command line, or add something like this at the end of your main():


char c = ' ';
std::cout << "Press q followed by enter to quit." << std::endl;
while(c != 'q')
std::cin >> c;

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