No brainer

Started by
7 comments, last by cmv 14 years, 9 months ago
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?
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.
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.
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.
How to keep the console window visible (in a non-suck fashion).
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.

[Website] [+++ Divide By Cucumber Error. Please Reinstall Universe And Reboot +++]

Quote:Original post by jpetrie
How to keep the console window visible (in a non-suck fashion).


You should sticky that. *prod*
Place a breakpoint on the closing brace of main:

int main(){} // <-- Breakpoint (F9) here!
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;

This topic is closed to new replies.

Advertisement