#include #include volatile bool hadCtrlC; BOOL WINAPI MyCtrlCHandler (DWORD type) { if (type != CTRL_C_EVENT && type != CTRL_BREAK_EVENT) { return 0; } hadCtrlC = true; return 1; } int main () { hadCtrlC = false; SetConsoleCtrlHandler (MyCtrlCHandler, 1); std::cout << "Waiting ..." << std::flush; while (!hadCtrlC) { Sleep (1000); std::cout << "." << std::flush; } std::cout << " done." << std::endl; std::cout << "Sleeping ... " << std::flush; for (int i=0; i<50; i++) { Sleep (100); } std::cout << "done." << std::flush; return 0; }