Different Ways for pausing

system ("PAUSE");

cin.ignore();

getchar();

There's another that I am forgetting. What are the differences between these different ways to pausing the screen? Are there any differences?
Last edited on
Yes, there are. The first one relies on the fact that the computer has to have a command called "pause", and I think that is the case of Windows only; Linux users cannot use that one.

The second one relies on the C++ variable std::cin and its inherent istream attributes; the third one I have never used it so I guess it corresponds to a C library that probably works the same as the second one.

Other than that, I guess all work. You should read http://www.cplusplus.com/forum/beginner/1988/ for some good tips on how to pause.
closed account (4z0M4iN6)
Ahaanomegas wrote:
There's another that I am forgetting.


Maybe that's the one, you forgot?

#include <conio.h>

_getch();


I will explain you the difference to getchar()

getchar() reads input from the standard io.
When you press a key except enter, the system still will pause.
When you press enter, getchar() delivers a character of the entered line.
The pause will not be ended, before you have read all the entered characters of the line.

_getch() reacts immediately to a key press on the keyboard
Just one thing. As I expected, conio.h was not present in Xcode. I'm not sure if it's Windows specific or VC++ specific, but that _getch() looked wrong for some reason.
closed account (4z0M4iN6)
Yes, it's some function of MS C/C++, it's not standard C++, because this is a PC hardware dependent function. Maybe you could find another one in Xcode. I don't know what Apple offers.
Last edited on
I think Xcode C++ doesn't differ at all from Vanilla, other than the obvious fact that the arguments that the system("Command here, please"); can successfully varies from other OSs' system commands, but that's still within the realm of Vanilla C++.

The language one is pretty much forced to use for anything other than console-based programs for MACs is Cocoa, which is Objective-C based. :( But I digress.
Last edited on
Topic archived. No new replies allowed.