判断规定时间内有无输入

  

 1 #include <iostream>
 2 #include <windows.h>
 3 #include <conio.h>
 4 using namespace std;
 5 
 6 int reaction(char *d);
 7 int main()
 8 {
 9     char d='a';
10     for(int i=0; i<10; i++)
11     {
12         if(reaction(&d))//有响应 
13             cout<<d<<endl;
14         else
15             cout<<"null"<<endl;
16     }
17  }
18  int reaction(char *d)
19  {
20      Sleep(400); 
21      if(!_kbhit())
22          return 0;
23      else
24      {
25          *d = _getch();
26          return 1;
27      }
28  }
29  
30  
31  
32  

这里的_getch() 函数表示输入一个字符不用回车

reaction()为响应函数

猜你喜欢

转载自www.cnblogs.com/guoyujiang/p/12110094.html