hi every one ...
i need a class time end to end my while loop
for example end the loop after 5 mins or at 2:30:00 pm
plz
i have to submite my project on wed.
hi every one ...
i need a class time end to end my while loop
for example end the loop after 5 mins or at 2:30:00 pm
plz
i have to submite my project on wed.
http://www.cplusplus.com/reference/clibrary/ctime/
You could check the time every iteration, although that seems kind of wasetful to be trying to break a while loop that way.
how can i say that
time_t a = 2:00:00;
You can't just do it that way. The problem with just specifying 2:00 is that you need to tell it 2:00 on which day.
Create a struct tm object and set the members to the exact time you want to stop at. When you have it set right, pass it to mktime(), and you'll get a time_t variable. Compare that to what you get from time() every iteration with the difftime() function, and you'll get the
difference in seconds between the two times.
It would seem a better way of doing this would be to create a separate thread that just sleeps until a given time and then sets a boolean flag that the other thread can check on whether to quit or not. This might be beyond the scope of your assignment, however.
Edit: Here's the FAQ link from this site about how to deal with dates and time: http://faq.cprogramming.com/cgi-bin/...&id=1043284392
Last edited by MacGyver; 05-20-2007 at 03:36 AM.