time

plz tell me how can i add a clock in my c++ program?i want it to tick at the top of my output..
You have to include ctime.h but here's a starting point: http://www.cplusplus.com/reference/clibrary/ctime/localtime/
A header as the other poster said would be a good place to start. To create the tick you'd probably want to start out with something like this in a custome time header, MyTime.h for example:

1
2
3
4
5
6
7
8
class MyTime

{private:
      // 1 _ticks = 1/100 of a second
      // 0 _ticks = 00:00:00.00 i.e. 12:00am 
      // a time is stored as a number of ticks since midnight
      // for example 1234567 ticks would be 3:25:45.67am 
      long _ticks;


You might also add the following for some static fields:

1
2
3
4
5
6
7
8
9
10
11
12
      // 8,643,999 _ticks = 23:59:59.99 i.e. 11:59:59.99pm
      static const long _lastTickOfTheDay = 8639999;
      // 4,320,000 _ticks = 12:00:00.00 i.e 12pm i.e. noon
      static const long _noon = 4320000;
      // _ticks per second;
      static const long _ticksPerSecond  = 100;
      // _ticks per minute;
      static const long _ticksPerMinute = 6000;
      // _ticks per hour;
      static const long _ticksPerHour = 360000;
      // _ticks per day
      static const long _ticksPerDay = 8640000;



=================================
UAT Online Student - Game Programming
Topic archived. No new replies allowed.