Pause Command in C++
pause() is a C++ method used to pause a program during execution. It allows the user to input or read data. The pause approach makes the system more readable and user-friendly by allowing the user to read the instructions before performing any task.
What is pause()?
The pause() function is used to pause the execution of the current program and wait for the user to press the enter key to terminate its operation. It serves the purpose of pausing the program, as its name implies. This method is window-specific. Only the Windows Operating System and earlier compilers like DOS support it. It can suspend a running program. To terminate the pause () method, the user can press enter or provide some time. When the pause method completes its operation, the remaining program starts to execute.
- Window specific
- Supported by the older compiler
- Fast and Efficient
Here, system() is a function that calls the operating system to perform the passed task. This method is present inside the <cstdlib> header file. It invokes Windows operating system to run the pause() function.
Return Type: The pause method has no return type.
Parameters: There are no parameters in the pause () function. Users can set a timer to automatically end the program in milliseconds.
1. Run pause() code on windows only.
2. The code can also be executed on MS-DOS compiler.
3. Modern Compiler won’t support this method it throws a command not found error.
Example 1: Below is the C++ program that will display messages with the pause method.
Welcome To Geeksforgeek Press any key to continue….. Done
Example 2: Below is the C++ program to print 1 to 10 numbers.
i = 1 i = 3 i = 5 Program Is Paused Press any key to continue….. Terminated i = 7 i = 9 Done
- Users can easily remember this method. It is useful to pause programs in older compilers like MS-DOS.
- To pause programs in the Windows system.
- The user can pause the program for as long as he wants by passing the time limit.
- The pause() function is not portable and is platform-specific. As the pause () method is window-specific, it will not work on other operating systems like Unix, Linux, etc.
- When the user calls the pause method, he also calls the system function. which all takes extra memory
- The remaining program will not execute until the pause () method is terminated or the user presses Enter.
- It’s slow.
- It’s insecure.