help me ... class time end

This is a discussion on help me ... class time end within the C++ Programming forums, part of the General Programming Boards category; hi every one ... i need a class time end to end my while loop for example end the loop ...

  1. #1
    Registered User
    Join Date
    May 2007
    Posts
    7

    help me ... class time end

    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.

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    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.

  3. #3
    Registered User
    Join Date
    May 2007
    Posts
    7
    how can i say that
    time_t a = 2:00:00;

  4. #4
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with FIFO QUEUE
    By jackfraust in forum C++ Programming
    Replies: 23
    Last Post: 04-03-2009, 08:17 AM
  2. deriving classes
    By l2u in forum C++ Programming
    Replies: 12
    Last Post: 01-15-2007, 04:01 PM
  3. program not working...please look at this
    By JOlszewski in forum C Programming
    Replies: 3
    Last Post: 01-30-2006, 09:33 PM
  4. The space time continueimnms mm... (rant)
    By Jeremy G in forum A Brief History of Cprogramming.com
    Replies: 32
    Last Post: 06-27-2004, 01:21 PM
  5. I apologize. Good bye.
    By doubleanti in forum A Brief History of Cprogramming.com
    Replies: 14
    Last Post: 05-03-2002, 06:51 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21