Hi...I want to create a timer so that after completing the time(suppose 10 sec) the control should come out of the function..Please note that am starting the timer inside the function..is this possible in c++...
Kumar_cr09
0
Newbie Poster
Recommended Answers
Jump to PostI suppose you could repeatedly call time() and exit the function when the desired amount of time has expired.
void foo() { time_t t1, t2; t1 = t2 = time(); // starting time while( (t2 - t1) < 10 ) // 10 seconds { // do something …
Jump to PostYou can use
clock()
to do this. You can find more about usingclock()
here. There's actually an exact example of what you want to do.
Jump to Postclock() is useless for his purpose. He needs a way to break out of input, such as gin.get(), after a certain time expires. There is no standard, or easy, way to do it. kumar may have to write his own custom keyboard input functions using os-specific api functions and threads.
All 9 Replies
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
Kumar_cr09
0
Newbie Poster
Kumar_cr09
0
Newbie Poster
Kumar_cr09
0
Newbie Poster
ravenous
266
Posting Pro in Training
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
ravenous
266
Posting Pro in Training
Kumar_cr09
0
Newbie Poster
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.