Input with a timeout in C++
<p>I want to have a program where the user have 10 seconds to enter the password. If the timer goes over 10 seconds, the program displays a message. My current code is this: </p>

<pre><code> #include &lt;iostream&gt;
 #include &lt;ctime&gt;
 #include &lt;string&gt;

int main(){
std::string password;

int start_s=clock();

int stop_s=clock();
if(stop_s-start_s &lt;= 0){

    std::cout &lt;&lt; "TIME RAN OUT!";
}
std::cout &lt;&lt; "Enter your password! \n";
std::cout &lt;&lt; "Password: ";
std::cin &gt;&gt; password;
std::cout &lt;&lt; "\n \n";

if (password == "password123"){

    std::cout &lt;&lt; "Correct!";
} else {
    std::cout &lt;&lt; "Wrong!";
}

}
</code></pre>

<p>This of course is not working... But I am not sure what to do next... Any ideas?</p>

<p>If you need more details, ask in the comments.</p>

<p><strong>EDIT:</strong></p>

<p>I just realized what the problem was... It took a time stamp and then quickly made another time stamp. And when the difference was found, it was below 0...</p>

<p>But I still don't know what to do next...</p>