What does the expression `system("pause")` do?

Asked

Viewed 9,812 times

1

What is the command for

system("pause");

?

  • 4

    I recommend you start reading first what the function system does, then try to understand what the parameter "pause" means.

  • Did any of the answers solve your question? Do you think you can accept one of them? Check out the [tour] how to do this, if you haven’t already. You would help the community by identifying what was the best solution for you. You can accept only one of them. But you can vote on any question or answer you find useful on the entire site.

2 answers

9

The function system() calls the operating system console (if it is no longer running) and executes a command in this application. In this case it is calling the command pause of the operating system that will make the console wait for a key and consequently your application will wait for it too.

It’s used to not let a quick test close. When using the command line to compile is not usually necessary, the use is for those who have become accustomed to using the IDE. It is recommended to use another mechanism that does not need to invoke the operating system to get the same effect, although in most cases it makes no difference.

  • 1

    Remember that this will not work on other systems than windows

  • @Denisrudneidesouza good.

  • 3

    That! As I answered a question about Python, where they use the same mechanism - either to pause, or to erase the screen with "cls": it’s the equivalent of you breaking the lock on your door, and thinking it’s okay to call the key ring every time you go in or out of the house. (a call to the function gets(), for example, it will pause the terminal until the user presses enter the same way)

  • 3

    As for other systems, those who use the os.system in Python think why you can choose the command between "cls" and "clear" with if sys.platform == 'nt':, they think they’re "stifling".

  • @jsbueno :D :D :D

-2

Basically the system("pause") will show what is being done in the program, without it, the program ran non-stop (pause)

  • 4

    Hi - thank you for your contribution and for the spirit of sharing. However, I think that in that case, it is worth going deeper into the implications of what it is to call the system - in this case, is to use the operating system to run a whole other program, separate from yours, to perform a trivial function.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.