Time problem

Hello guys! I have a question for you and I'm sorry if I'm wasting your time.
I want to know if there is any function that can help you to introduce a value in a certain time.
For example :
In the next 3 seconds : cin>>n;
If you don't introduce a value in 3 seconds the program will go further.
closed account (j3Rz8vqX)
andywestken:
There is no standard C++ solution to your problem. If you are working with Windows, two possibilities are (1) conio (#include conio.h and then use kbhit/getch or _kbhit/_getch - the _-prefix is preferred by Visual C++), and (2) WIN32 GetStdHandle and GetAsyncKeyState.

If you search this site for info on either kbhit or GetAsyncKeyState, you will find various examples of their use. For example: "i need a code for takin input fo 2 secs;"
http://www.cplusplus.com/forum/beginner/5619
But if you're keen enough -- and mad enough -- you'll prob find a Linux port of conio...

Quoted from the below link:
http://www.cplusplus.com/forum/beginner/54738/
Last edited on
Hmm I wrote about kbhit function and i solved my problem:

Sleep(2000); /* need windows.h */
if(kbhit()) ....


TY
Topic archived. No new replies allowed.