Hi,
Let say I printed something out to the screen,
cout << "Love one another";
how do I make it so that so the program will pause until the user hits "enter"??
Is there some Pause, Wait command??
Printable View
Hi,
Let say I printed something out to the screen,
cout << "Love one another";
how do I make it so that so the program will pause until the user hits "enter"??
Is there some Pause, Wait command??
cout << "Love one another";
cin.get();
-Prelude
I think the prelude is very nice...no pun intended :D
...........
getch(); // waits for any key being pressed
............
#include <stdlib.h>
system("pause");
// print to the screen "Press any key to continue..." and waits for user's input....
..................
>getch(); // waits for any key being pressed
Nonstandard, may not work on all implementations and a bad idea in general to use unless you have to.
>system("pause");
To my knowledge this only works on DOS and Windows systems, and the system function is godawful slow.
-Prelude
while (!kbhit()); should also work, but I believe it's nonstandard as well.
BTW getch() will continue if the user presses any key at all. To check for enter being pressed, try:
while (getch() != 13);
Here's a standard way...
Code:char wait;
cin>>wait;
The fastest too
Yeah but you could gunk up your buffer doing that.
I love this forum, ...thank you to everyone who replied, appreciate the advice and suggestions :D
another quick question:
I don't remember exactly, but once upon a time I heard that "cout" outputs to a buffer. I was wonder if there is a command to purge that buffer (i.e. to display the text in that buffer immediately). I'm having timing problems with the getin() and system("pause").
cout << "WASABI";
getin() // or system(pause)
my program would pause first, then when i press enter,..."WASABI" would then print (not good :[)