Я пишу свою первую настоящую программу на C ++, и мне просто интересно, почему _getch () действительно несколько раз обнаруживает, что я нажал клавишу. Обычно требуется 2 или 3 попытки, прежде чем он на самом деле подхватывает его и делает то, что должен, а первые несколько раз он просто действует так, как будто ничего не произошло. Вот весь соответствующий код:
#include <iostream>
#include <conio.h>
int main()
{
using namespace std; // so i don't have to do 'std::cout' for every time I want to print, among other things
cout << "Bag's Example Program\n\n";
system("pause"); // waits for user input, with a "Press any key to continue" message
bool chosen = false;
while (chosen == false) {
system("cls"); // clears the screen
cout << "Enter a string: ";
string words;
cin >> words;
cout << "You entered: " << words << "\n\nIs this correct? (Y/[N]): ";
_getch(); // waits for user input
if ((_getch() != 121) || (_getch() != 89)) { // if user's keystroke was NOT the 'y' key
cout << "user selection was NO\n";
}
else { chosen = true; }
}
}