This question already has answers here:
Capture characters from standard input without waiting for enter to be pressed
                                
                                    (15个答案)
                                
                        
                                2年前关闭。
            
                    
我想知道是否有可能从按下键的while循环中退出,例如,执行一个加载数字的程序,直到您按下“ q”。
我在linux上工作,我想做这样的事情:

do{
   cin >> num;
   numbers.push_back(num);
}while(key(q));


不归

最佳答案

char key;
bool loop = true;
while(loop){
    cin >> key;
    if(key == "WHATEVER MATCHED") loop = false
}


要么

char key;
while(true){
    cin >> key;
    if(key == "WHATEVER MATCHED") break;
}

关于c++ - 如何管理C++键盘事件? ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41748869/

10-10 06:01