Input help

I am self teaching myself C++, it's been a slow grueling process, but I am making headway. But, unfortunately I am stuck. This has got to be real simple. However I cannot find the how to do it in the tutorial?

Basically, I want to have a line that says "Hit (B) to go back or (X) to exit." and the have a simple conditional: if the key hit equals "B" or "b" then go to line 1 (and of course much the same for "X" or "x").

The cout part isn't a problem. But from what I read every cin command requires that you to hit return to input a value into a variable. I don't want to do it that way. I want to be able to hit one key and immediately upon hitting that key an event happen (exit of the program, go to line 1, etc.). Can somebody tell me how I can accomplish this?

I would greatly appreciate any help anyone can give.

Thanks,
Elaphe
Last edited on
P.S. If anyone knows of a good tutorial online please let me know.
Unfortunately, as far as I know, there is no easy way to do that. The only way I could think of is to directly use the API for your desktop system (e.g. windows.h) to wait for a key press, and then process the key press. In other words, there is not really a way you can do this in "standard" C++ (I could be wrong).

By way of good C++ tutorials, the one on this site (http://www.cplusplus.com/doc/tutorial/) is pretty good, as well as www.learncpp.com.


EDIT:
If you REALLY want to, you could use the (absolutely non standard) conio.h getch() function, but only use that as a last resort. Anyway, is pressing return on input really too much to ask?
Last edited on
You are looking for getch() function from conio library
Who know this would be so difficult? Is there a good tutorial on how to use the getch() command to do what I want it to? Please help!
Topic archived. No new replies allowed.