Public Group

# No brainer

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

## 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 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 on other sites
Quote:
 Original post by MH6Or 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 on other sites
Quote:
Original post by Captain_Thunder
Quote:
 Original post by MH6Or 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 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 on other sites
Quote:
 Original post by jpetrieHow to keep the console window visible (in a non-suck fashion).

You should sticky that. *prod*

##### Share on other sites
Place a breakpoint on the closing brace of main:

int main(){} // <-- Breakpoint (F9) here!

##### 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;

1. 1
2. 2
3. 3
Rutin
13
4. 4
5. 5

• 26
• 11
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633700
• Total Posts
3013420
×