| | |
Why `system("pause")' shouldn't be used?
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
1
#4 Oct 9th, 2009
•
•
•
•
Yes but, why don't use system("pause") at all? I mean what's wrong with it?
•
•
•
•
>system("pause");
This is all kinds of wrong. First, while system is a standard function and thus portable, the argument you pass to it cannot be portable because it relies on the system command interpreter. If you move the code to a different system, the command interpreter will probably be different (or not available!) and system("pause") could do something completely different or break.
Second, system is unsafe because it doesn't verify that the pause program is the one supplied by the system. It may be a malicious program bent on wreaking havoc.
Third, system is sloooooooow. Dreadfully, painfully, agonizingly sloooooooow. This isn't really a problem if you call it once, like here, but system should really be avoided in favor of better alternatives. My code shows one of those alternatives. It requires the user to hit return, but it's portable and does the job admirably with no noticeable inconvenience to the user.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
1
#6 Oct 10th, 2009
•
•
•
•
* Don't use system("pause") to pause your program if possible. Use getchar( ) if you are using C and cin.get( ) if you are using C++.
Why is that? A reasonable explanations for those tips would help to learn.
•
•
•
•
Yes but, why don't use system("pause") at all? I mean what's wrong with it?
"Never argue with idiots, they just drag you down to their level and then beat you with experience."
![]() |
Similar Threads
- system( "PAUSE" );!!!! (C++)
- system("pause"); (C++)
- system("PAUSE") (C++)
Other Threads in the C++ Forum
- Previous Thread: Add Text To multiline textbox
- Next Thread: c++ project for 12th
| Thread Tools | Search this Thread |
api array based binary c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock wordfrequency wxwidgets






