title: How to use a timer in C++ to force input within a given time?
body: <p>I want to implement a time out feature in C++.  </p>
  
  <p>If the user does not input the value within 2 seconds then the program must display the time-out statement and ask the input again  </p>
  
  <p>EX(OUTPUT SCREEN):  </p>
  
  <pre><code>Timer=0;  
  Please enter the input:       //if input is not given within 2 seconds then  
  Time-out: 2 seconds  
  Timer again set to 0  
  Please enter the input:  //if input is not given within 2 seconds then  
  Time-out: 2 seconds  
  Timer again set to 0  
  Please enter the input:22  
  Data accepted  
  Terminate the program`
  </code></pre>
  
  <p>Code:  </p>
  
  <pre><code>#include&lt;iostream&gt;  
   #include&lt;time.h&gt;  
   using namespace std;  
   int main()  
  {  
      clock_t endwait;  
      endwait =  2000 ;  
     cout&lt;&lt;endwait;  
     while (clock() &lt; endwait)  
    {  
           cout&lt;&lt;"Please enter the input:";  
    }  
     return 0;  
  } 
  </code></pre>
  
  <p>I have worked on the above code. But this happens only while entering the WHILE loop. How shall i do it in a way so that, I get the required output.</p>