I want to read a single character from the input stream and take immediate action when I do so. For example,
char answer;
cout << "Type 'y' to continue" << endl;
answer = cin.get();
if (answer != 'y') return 0;
// continue
The problem is that when I use cin.get(), getchar(), cin.peek(), cin.read(), etc., it seems to be necessary to terminate the input of "y" with a newlin character, (the Enter key, or "\n"
before the code will begin reading the buffer and start processing the input stream. How can I avoid this, i.e., to have the program examine the answer character immediately and take action without entering a newlin?
char answer;
cout << "Type 'y' to continue" << endl;
answer = cin.get();
if (answer != 'y') return 0;
// continue
The problem is that when I use cin.get(), getchar(), cin.peek(), cin.read(), etc., it seems to be necessary to terminate the input of "y" with a newlin character, (the Enter key, or "\n"