小编Ank*_*ane的帖子

如何在C++中使用计时器在给定时间内强制输入?

我想在C++中实现超时功能.

如果用户未在2秒内输入该值,则程序必须显示超时语句并再次询问输入

EX(输出屏幕):

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`
Run Code Online (Sandbox Code Playgroud)

码:

#include<iostream>  
 #include<time.h>  
 using namespace std;  
 int main()  
{  
    clock_t endwait;  
    endwait =  2000 ;  
   cout<<endwait;  
   while (clock() < endwait)  
  {  
         cout<<"Please enter the input:"; …
Run Code Online (Sandbox Code Playgroud)

c++ timer sliding-window

7
推荐指数
1
解决办法
2万
查看次数

标签 统计

c++ ×1

sliding-window ×1

timer ×1