Thread: time

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    35

    time

    Using the simple iostream.h stuff like cout << "blah"; , I want to make a message appear every 350 milliseconds. How would I do that?

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Use sleep().

    -----
    for (;;
    {
    cout << "blah" << endl;
    sleep(350);
    }
    -----

    Kuphryn

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    35
    1. sleep is undeclared identifier.
    2. does it put the entire program on hold?

  4. #4
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    #include <afxwin.h>

    Yes, I believe sleep() will halt the enter program.

    Kuphryn

  5. #5
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >sleep is undeclared identifier.
    So write it yourself.
    Code:
    #include <ctime>
    
    void sleep ( long m )
    {
      clock_t limit, cl = clock();
      limit = cl + m;
      while ( limit > cl )
        cl = clock();
    }
    >does it put the entire program on hold?
    This is implementation specific. One implementation may write a sleep or delay function which is thread friendly and another may not. The code I gave above is not, but you can write code which gives the feeling of synchonization through use of time-sharing.

    -Prelude
    My best code is written with the delete key.

  6. #6
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    is this a dos program? you don't have events in dos. how are you going to continue doing other stuff while you wait for a timer to fire? Maybe I'm confused. probably.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to get current time
    By tsubasa in forum C Programming
    Replies: 3
    Last Post: 05-01-2009, 02:03 AM
  2. Replies: 11
    Last Post: 03-29-2009, 12:27 PM
  3. Help with assignment!
    By RVDFan85 in forum C++ Programming
    Replies: 12
    Last Post: 12-03-2006, 12:46 AM
  4. calculating user time and time elapsed
    By Neildadon in forum C++ Programming
    Replies: 0
    Last Post: 02-10-2003, 06:00 PM
  5. time class
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 12-11-2001, 10:12 PM