I have seen various types of pause implemented in C++ eg:
getch()
cin.get()
system("pause>nul")
But I would like to know which of them is the most correct or recommended to use, or if there is no difference.
I have seen various types of pause implemented in C++ eg:
getch()
cin.get()
system("pause>nul")
But I would like to know which of them is the most correct or recommended to use, or if there is no difference.
There are several differences:
That only works if there is a command
pause
that the operating system 's shell can execute. On Linux, for example, it gives an error oforden no encontrada
.Also, it uses more resources than the others: it needs to call an external program (the command interpreter); if it recognizes the order, it will execute it. If it doesn't recognize it, it will call another program (or give an error). A waste, come on.
This is not portable . It depends on whether the library used provides it, but we cannot assume that it exists in all compilers. Same example as above: on Linux, it doesn't work.
This is the correct way. It belongs to the C++ standard, so it will be present in all compilers that conform to it.