how to take input within a time limit.

Nov 11, 2011 at 12:36pm
i want to take input in an intergr with in a time if user does not give input within time then program should skip input process and programe set input in varibal atomatically.
Last edited on Nov 11, 2011 at 12:37pm
Nov 11, 2011 at 1:04pm
mate you should really use search option before posting. Read the rules.

here: http://www.cplusplus.com/forum/beginner/12216/
Nov 11, 2011 at 5:51pm
@Jan - the post you sent the link to -- "How can I measure how many milliseconds have elapsed?" -- does not answer the question. The problem is how to give up waiting for input after a certain time, not checking how long it took to enter input.

Personally, I find this site's search engine to be a bit dumb (ever since I found it couldn't "see" Qt). So now I generally use Google with a "site:www.cplusplus.com" term in the seach criteria.

Anyway...

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...

Andy
Last edited on Nov 11, 2011 at 5:53pm
Topic archived. No new replies allowed.