title: "Safely" terminate a running C++ program on keypress?
body: <p>I'm trying to write a simulation that will carry on running until I press a certain key (like 'q' for quit). Then after I press that, I want the program to finish writing the data its currently writing, close files, then gracefully exit (as opposed to just pressing ctrl+c to force the program to stop). Is there any way to do this on C++?</p>
  
  <p>Thanks</p>