我有一个计时器设置,可以计算到'x'的时间。 所以在这个while循环中,如何让程序以特定的间隔触发一个函数(例如每1分钟,每2秒等)
const double LIMIT = 5.0 ;
int main(){
cout << "-- Email Simulation --" << endl;
Timer timer;
timer.start();
while( timer.elapsedSeconds() < LIMIT ){
// do stuff here
}
timer.stop();
cout << "Elapsed Time : " << timer.elapsedSeconds() << "s" << endl;
return 0;
}
我尝试使用这种方法,但不止一次触发该功能,这不是我想要的。
if( timer.elapsedSeconds() == x ){
// do stuff
}