How do I REALLY process a single keypress without needing ENTER?

Really, all I want is to have a menu.

A - first option
B - second option
C - third option

A, B, C or Q to quit ?

I don't want to have the user need to press ENTER, just A or B or C or Q or the lower-case versions thereof.

This cannot be rocket science, but trying to make sense of the questions/advice I've seen on this site dealing with this is making me dizzy.
I don't think this is possible with standard c++. If your on windows you can use conio.h but this is a non standard header file.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <conio.h>
#include <iostream>
using namespace std;

int main()
{
     std::cout << "A - first option" << std::endl;
     std::cout << "B - second option" << std::endl;
     std::cout << "C - third option" << std::endl;

     char option = _getch();
     switch(toupper(option))
     {
        case 'A':
            std::cout << "You picked A" << std::endl;
            break;
        case 'B':
            std::cout << "You picked B " << std::endl;
            break;
        case 'C':
            std::cout << "You picked C " << std::endl;
            break;
        default:
            std::cout << "Error invalid option " << std::endl;

     }
}
Thank you. I have conio.h for other reasons so this will work splendidly.

Topic archived. No new replies allowed.