#include#include "CTimer.h" void myCallback(CTimer* timer) { std::cout << "Timer triggered!" << std::endl; // stop the timer timer->stop(); } int main() { // create a timer that triggers after 5 seconds CTimer timer(5000, myCallback); // start the timer timer.start(); // keep the program running while (true) { // do some other work } return 0; }
#includeBoth of the above examples demonstrate how to use CTimer to create and manage timers that trigger at specific intervals. CTimer is included in the Boost C++ Libraries.#include "CTimer.h" void myCallback(CTimer* timer) { std::cout << "Timer triggered!" << std::endl; } int main() { // create a timer that triggers every 2 seconds CTimer timer(2000, myCallback, true); // start the timer timer.start(); // keep the program running while (true) { // do some other work } return 0; }