how can i configure cin to wait until enter is pressed?
how can i configure cin to wait until enter is pressed?
C++ Makes you Feel Better
"Gravity connot be held reponsible for people falling in love"--Albert Einstein
Please elaborate; I can't think of a case where cin doesn't wait until enter is pressed.
normaly cin wait for a char or number to be entered and then pressed i mean that cin wait for just a enter
C++ Makes you Feel Better
"Gravity connot be held reponsible for people falling in love"--Albert Einstein
Oh, I get it.
No, cin by itself doesn't do that, but you can use the function cin.get() to do that.
Just add this:
...where you want it to do that.Code:cin.get();
Oh, and if the program skips over it without waiting, add this right before it:
That should do it.Code:cin.ignore('\n', 10);
Alternately, you could also use this:
...to make it wait until any key is pressed. The downside of that method is that it has a predefined message that it displays when it waits.Code:system("PAUSE");
Last edited by Gabu; 07-22-2002 at 04:28 AM.
I think you could also use getch by asking it to look for the ASCII value of return, I think its '13' I did a similar thing in an exercise a bit ago.
declare the control variable as an int, so it looks for ASCII value.
I'm pretty sure that should work.Code:int enter; while (enter!='13') { getch(enter); if (enter != '13') { cout<<"do it again."; } }
Last edited by UnclePunker; 07-22-2002 at 06:06 AM.
Compiler == Visual C++ 6.0"Come Out Fighting."
While 'getch()' is an option, be aware that it doesn't take an argument. (This will become apparent when you attempt to compile the code, of course, but I thought I'd throw it out.)
-SkipperCode:#include <iostream> #include <conio.h> int main() { char key; do { clrscr(); // makes it look like nothing's happening std::cout << "Press ENTER to continue..."; key = getch(); }while (key != '\r'); // C++ (not ASCII) escape char for carriage return std::cout << "\n\nThanks for finally pressing the ENTER key!"; getch(); return 0; }
"When the only tool you own is a hammer, every problem begins to resemble a nail." Abraham Maslow