jeudi 7 avril 2022

Detecting user input spent time under C++

I am building a simple game and I need to set some options, including user timeout to end the game. The following piece of code will clarify what I want:

do {
    //some code
    cin >> ...a char ...;
    if( duration > timeoutLimit)
    {
        cout << "took too long for input ... max imput time reached" << endl;
        break;
    }
}while(...something...);

This is going to work inside de loop and it breaks, if during the user inputs, that may be several, the maximum time allowed is reached. Using clock() I only get the time spent on performed calculations and not the time spent with user input which is what I want.

Aucun commentaire:

Enregistrer un commentaire