I want to make a clock in realtime, but every time I print out a new time it never updates, how come?
Timer.h
main.cpp fileCode:#ifndef _TIMER_ #define _TIMER_ #include <ctime> class Timer { clock_t counter; public: Timer(): counter(0) {}; bool elasped(clock_t ms) { clock_t tick = std::clock(); if(tick - counter >= ms) { counter = tick; return true; } return false; } }; #endif
Code:int main() { Timer timer; time_t now; time(&now); while(true) { if(timer.elasped(1000)) cout << ctime(&now); } }