等待特定时间范围的输入 [英] Waits for input for certain time frame

查看:100
本文介绍了等待特定时间范围的输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是C ++的初学者,并尝试完成一个简单的功能。



假设我有前3行:



int age;

cout<<请输入您的年龄<< endl;

cin>> age;





我希望这个函数等待30秒,如果有任何整数输入,则执行函数A,否则有没有用户输入并且时间到了,执行功能B.



我知道函数sleep可以很好地等待,但程序会等到有输入,30秒后不会停止。



请帮助,谢谢。

I am just a beginner of C++ and trying to get a simple function done.

Lets say i have these first 3 lines:

int age;
cout<<"please enter your age"<<endl;
cin>>age;


I want this function to wait for 30 seconds, if there is any input of integer, function A is executed, else there is no input by the user and the time is up, function B is executed.

I know the function sleep works well for waiting, but the program waits until there is input, not stopping after 30 seconds.

Please help, thank you.

推荐答案

它实际上并不像人们想象的那么简单,也许此链接 [ ^ ]将有所帮助。
It's actually not as simple as one would think, maybe this link[^] will help.


这篇关于等待特定时间范围的输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆