萬盛學電腦網

 萬盛學電腦網 >> 網絡編程 >> 編程語言綜合 >> c++實現每隔1秒鐘執行一段程序

c++實現每隔1秒鐘執行一段程序

 #include <iostream>
#include <ctime>
using namespace std;

int getTime() {
return clock()/CLOCKS_PER_SEC;
}

int main() {
int i = 0;
int lastTime = 0;
while (1) {
int now = getTime();
if (now - lastTime > 0) {
cout << ++i << endl;
lastTime = now;
}
}
return 0;
}

copyright © 萬盛學電腦網 all rights reserved