Tag: kbhit

在Linux上使用kbhit()和getch()

在Windows上,我有以下代码来查找input而不中断循环: #include <conio.h> #include <Windows.h> #include <iostream> int main() { while (true) { if (_kbhit()) { if (_getch() == 'g') { std::cout << "You pressed G" << std::endl; } } Sleep(500); std::cout << "Running" << std::endl; } } 但是,看到没有conio.h ,在Linux上实现这个同样的事情最简单的方法是什么?