Continuous input

Hi, I am trying to make a calculator and was wondering if there was a way to evaluate input before submitting it? For example
1
2
3
4
5
6
7
8
9
10

char = ch;

while (cin >> ch)
{
    if (ch == 'q')
       break;
    else
      stream.pushback(q);
}


The above does not work as it waits for me to finish input with an enter and then checks for q. Is there a way to check for q with every key press?
Last edited on
This type of thing is a PITA (Pain In The Ascii) to do in the console. You can find ways to directly poll the input stream with external libraries but I suggest you start learning GUI libraries instead. With a GUI you have simple event handling that would allow you to respond when a uses types a character into a text box for instance.

EDIT: If you REALLY need to do this in a console program check into conio and curses (pcurses and ncurses are later versions). They offer functions that will help... at least in Windows.
Last edited on
Cheers, thanks.
Last edited on
Topic archived. No new replies allowed.