使用c++测试ctime模块,发现将 clock_t start, end; 放在 main 中没问题,但是放在全局变量中出错,是什么原因?
# include <iostream>
# include <ctime>
using namespace std;
clock_t start, end;
int main(){
int ans = 0, times=1e8;
start = clock();
for (int i=0; i<times; i++){
ans ++;
}
end = clock();
double endtime = (double)(end-start) / CLOCKS_PER_SEC;
cout << "Total time: " << endtime << endl;
return 0;
}