Once again, Y/N?

Hello to all,

How do I avoid the enter after either Yes or No? I am using cin in C++ but is there another way to avoid having to use the enter after the Y or N?

Thanks in advance,

VGCM66
I suppose you are talking about a console application, and you want something like

Quit?[Y/N]Y


Where the user does not have to press "Enter" after entering the Y sign?

If you're using windows, you may have a header called <conio.h> that provides a function called getch() that does just that.

http://en.wikipedia.org/wiki/Conio.h

That header is not part of the standard though, it would be better if you'd just let the user press enter.
Thanks hanst99,

It worked. I see your point but since this program will not go anywhere except with me I will rather use the getch() on this one.

Thanks again,

MAB
One last one please,

How do I do an infinite loop until any keyboard key is depressed? What function???

Thanks,

MAB
Never mind, I founded "while (!_kbhit())"

Thanks,

MAB
JSYK, that while loop is CPU-intensive. Better to use one of the OS wait functions, like I did here (with my waitforkeypress() functions).

http://www.cplusplus.com/forum/beginner/28855/3/#msg159698

Good luck!
Also, it's not an infinite loop if it ends... right?

Also, it's not an infinite loop if it ends... right?


I see your point, but I also usually call my loops "infinite" if the number of iterations is actually "indefinite".
I was just being a smartass :)
Topic archived. No new replies allowed.