Quote:
BTW, why should one not use system("pause") at the end of a console program like this?
Because it's Flat Out Stupid. It is equivalent to things like "We don't call delete on this particular pointer, because the OS will clean up the memory when our process dies" and "the user has selected the quit option, so let's quit real fast: int *p = 0; *p = 10;."
And so on. Yes, they achieve the desired end result, but they do it in obviously stupid and potentially dangerous, non-portable ways. Note that non-portability is generally the least of the problems here.
When you run a program built for a console environment from your IDE, the IDE spawns a console environment. The program runs to termination and quits. At this point, most console environments will terminate themselves because they are smart enough to know that they were launched with the express purpose of running a single command (your executable). This is the correct, desired behavior of both the console environment and your program.
A program built for a console environment is designed to run in a console environment. Artificially pausing the program prior to exit is counter-intuitive in that environment. Think of how annoying it would be use to the command program if every time your listed a directory, changed directories, et cetera, you were promted to "press a key to continue." Think of how impossible it would be to write a batch file uses a program that requires user input to fully terminate itself, even if it otherwise requires no user interaction. It's exactly the same as the obnoxious "You picked the quit option, are you sure you want to quit?" prompts (these are forgivable only if quitting would cause you to lose state or information, such as when you have unsaved work; otherwise they are redundant and counter-intuitive). Just don't do it.
Any decent IDE (including Visual Studio -- it's either Run or Run Without Debugging, I tend to forget which, my keymapping is nonstandard, and I don't have VS installed on the machine I'm currently at) has a means to invoke a console-environment program and persist the console window. This could be as simple as generating a batch file that calls your program, and then calls "pause" or some other platform-specific delay mechanism. The difference, however, is that that method does not hard-code incorrect delay logic into your program.