How to read until ESC button is pressed from cin in C++
I'm coding a program that reads data directly from user input and was wondering how could I read all data until ESC button on keyboard is pressed. I found only something like this: std::string line; while (std::getline(std::cin, line)) { std::cout << line << std::endl; } but need to add a portable way (Linux/Windows) to catch a ESC button pressed and then break a while loop. How to do this? EDIT: I wrote this, but still - works even if I press an ESC button on my keyboard: #include <iostream> #include <string> using namespace std; int main() { const int ESC=27; std::string line; bool moveOn =