-1

I have a simple code as below.

    int a, b;
    cin >> a >> b;

If the user only inputs one number, the program will hang there waiting for another input. How do I stop the situation automatically and let the user to enter two numbers again if there is no input for a time, like 30 seconds?

webber.c
  • 1
  • 1

1 Answers1

0

There is no easy / universal way to do so. There are separate methods for Linux (alarm, signal handlers, followed by manual stream flushing and resetting) and Windows (not sure -- implement your own readline using raw keyboard input?), but they are all quite complicated and hard to get right.

theamk
  • 1,420
  • 7
  • 14