Jump to content
  • Advertisement
Sign in to follow this  
XandX2005

No brainer

This topic is 3256 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

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
Advertisement
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
A solution that lets you use the debugger and still keep the window open is to bung a breakpoint on the terminating brace of your main method.

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
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!