Thread: clock

  1. #1
    Registered User
    Join Date
    Dec 2001
    Posts
    479

    clock

    how do i make a clock ticker to display in the same place
    u know like an ordinary digi clock


    i have heard u should use setw()?
    how does it work?
    can someone show me an example please
    p.s
    i don't want to use the computers own time or anuthing like
    i just want to do all the parts by hand!

  2. #2
    Fingerstyle Guitarist taylorguitarman's Avatar
    Join Date
    Aug 2001
    Posts
    564
    Check out the functions in the time.h header.

    I hate to tell you but at some point you're going to have to rely on the system for the time. (Unless of course you just ask the user for the current time constantly)

  3. #3
    Registered User
    Join Date
    Dec 2001
    Posts
    479
    yes that was just what i meant the time.h
    i dont want to use

  4. #4
    Fingerstyle Guitarist taylorguitarman's Avatar
    Join Date
    Aug 2001
    Posts
    564
    Well good luck then.

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > yes that was just what i meant the time.h
    > i dont want to use
    time.h doesn't draw the time, nor print the time, it just tells you the time

    It's up to you to put that on screen in any way you can think of doing it.

  6. #6
    Registered User
    Join Date
    Dec 2001
    Posts
    479
    about the time in the same spot

    any suggestions?

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    That would require more information about which OS and compiler you are using.

    Cursor positioning and graphics are not standard.

  8. #8
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    As you haven't given us your compiler, this'd be a start -

    Code:
    #include <iostream> 
    
    using namespace std;
    
    
    int main() { 
    
        int time = 10000000;
    
        while(time<99999999)
        {
            cout << time++;
            cout << "\b\b\b\b\b\b\b\b";
        }
       
    }

  9. #9
    Registered User
    Join Date
    Dec 2001
    Posts
    479
    the last code was very helpful thanks
    i tried to write something like this

    #include <iostream.h>




    int main() {

    int time = 10000000;

    while(time<99999999)

    { cout<<"timeis:";

    cout<<"\b\b\b\b\b\b\b\b\b\b\b";

    cout << "\b\b\b\b\b\b\b\b";
    cout<<time++;
    }
    return 0;
    }

    i just added "thetimeis:"and some\b:s but the timeis doesn't show when i run it!

  10. #10
    Fingerstyle Guitarist taylorguitarman's Avatar
    Join Date
    Aug 2001
    Posts
    564
    Oh that's how you do time? I never knew you could loop and tell time.
    Although, I should point out that it will loop very fast and not be very useful.

    I think a larger concept is being missed here.
    To each his own.

  11. #11
    Registered User
    Join Date
    Dec 2001
    Posts
    479
    not really at least one number changes after the same time it takes for a sec.

    <I think a larger concept is being missed here.
    <To each his own.

    ?
    what?
    did u mean?

  12. #12
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    cout is an object of class ostream. Inside cout there is a buffer .This buffer is only emptied when one of these occur.
    1) an endl in the stream .... endl.... not \n
    2) the flush manipulator in the stream. i.e. cout<<"This will be shown because buffer is flushed"<<flush;
    3) an input operation through istream. This is because cout is tied to cin so that everytime cin is used cout flushes its buffer.
    4) when the buffer is full

    Now I'll let you work out your missing output problem.....
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Logical Error in Clock program
    By SVXX in forum C++ Programming
    Replies: 0
    Last Post: 05-10-2009, 12:12 AM
  2. Outside influences on clock cycles? (clock_t)
    By rsgysel in forum C Programming
    Replies: 4
    Last Post: 01-08-2009, 06:15 PM
  3. Clock Troubles
    By _Nate_ in forum C Programming
    Replies: 22
    Last Post: 06-19-2008, 05:15 AM
  4. clock program
    By bazzano in forum C Programming
    Replies: 3
    Last Post: 03-30-2007, 10:12 PM
  5. System clock
    By bazzano in forum C Programming
    Replies: 10
    Last Post: 03-27-2007, 10:37 AM