Does it answer your question?
system("pause"); - Why is it wrong?
Using system("pause"); is Ungood Practice™ because
It's completely unnecessary. To keep the program's console window open
at the end when you run it from Visual Studio, use Ctrl+F5 to run it
without debugging, or else place a breakpoint at the last right brace
} of main. So, no problem in Visual Studio. And of course no problem
at all when you run it from the command line.
It's problematic & annoying when you run the program from the command
line. For interactive execution you have to press a key at the end to
no purpose whatsoever. And for use in automation of some task that
pause is very much undesired!
It's not portable. Unix-land has no standard pause command.
The pause command is an internal cmd.exe command and can't be
overridden, as is erroneously claimed in at least one other answer.
I.e. it's not a security risk, and the claim that AV programs diagnose
it as such is as dubious as the claim of overriding the command (after
all, a C++ program invoking system is in position to do itself all
that the command interpreter can do, and more). Also, while this way
of pausing is extremely inefficient by the usual standards of C++
programming, that doesn't matter at all at the end of a novice's
program.
So, the claims in the horde of answers before this are not correct,
and the main reason you shouldn't use system("pause") or any other
wait command at the end of your main, is the first point above: it's
completely unnecessary, it serves absolutely no purpose, it's just
very silly.