Using the system("pause") command in C++ With Examples

In this article, we’ll take a look at using the system(“pause”) command in C++.

Before going through this article, note this the system("pause") command is only available in Windows Systems.

This means that you cannot use this from any Linux / Mac machine.

The system() command

Before going through the system(“pause”) command, let’s understand what system() does.

The system() function performs a call to the Operating System to run a particular command.

Note that we must include the <cstdlib> header file.

This is very similar to opening a terminal and executing that command by hand.

For example, if you want to use the “ls” command from Linux, you can use system("ls").

If you are having any Linux/Mac machine, you can try the below code.

Possible Output

Now that we’re a bit clear on what system() can do, let’s look at the system(“pause”) command.

Using system(“pause”) command in C++

This is a Windows-specific command, which tells the OS to run the pause program.

This program waits to be terminated, and halts the exceution of the parent C++ program. Only after the pause program is terminated, will the original program continue.

If you’re using a Windows machine, you can run the below code:

Output – From Windows System

As you can observe, the pause command was indeed executed when our if condition i = 5.

After we hit enter, we terminated the pause program, and resumed our loop in C++ program!

Disadvantages of using the system(“pause”) command

The main pitfall of system(“pause”) is that this is platform specific. This does not work on Linux/Mac systems, and is not portable.

While this works as a kind of a hack for Windows systems, this approach may easily cause errors, when you try to run the code on other systems!

Therefore, I would suggest some other alternative ways to pause and resume a program, such as using signal handlers.


In this article, we learned how we could use the system(“pause”) command in C++. For similar content, do go through our tutorial section on C++ programming!


By admin

Leave a Reply