I'm currently writing something of a quiz program. This program throws questions at the user until a specified time limit runs out. How it's set up now is the quizzing functionality runs in a boost thread and the timing aspect is handled by a timed_join() on that thread. The problem I'm encountering is when the user is answering a question using cin, the thread will go past the time limit that has been established. Is there a way to have it interrupt the cin call?
You can use Boost.Asio to read from cin asynchronously as described here - updated link to example code is here.
You can read the input character by character in a non-blocking read by using getchar, getch or getche. If you've been looping long enough to reach the timeout, then stop looping :).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With