Stopping an infinite loop in C++ when key is pressed [duplicate]
问题 This question already has answers here : How to detect key presses in a Linux C GUI program without prompting the user? (4 answers) Closed 5 years ago . I have a program as given below: #include<iostream> using namespace std; int main() { while(true) { //do some task if(Any_key_pressed) break; } return 0; } how can exit from the loop if any key is pressed. C++ Compiler: GCC 4.2 and higher OS: Linux-Mint Thanks 回答1: Standard C++ doesn't offer a way to do this. You will need a platform-specific