MS Visual Studio 2012(cl.exe命令行编译器)。为什么我会收到错误(阅读评论)?
// C89
#include<ctype.h>
#include<time.h>
int main(void){
long int i;
long int n = 1000;
clock_t cur_time1 = clock();
clock_t cur_time2;
long double secs;
for(i = 0; i < n; ++i);
cur_time2 = clock();
// Here I get an error C2059
secs = long double(cur_time2 - cur_time1)/long double(CLOCKS_PER_SEC);
printf("For the thousand: %lf sec.\nFor the billion: %lf sec.\n",
secs, secs * 1000000);
getchar();
}
谢谢。
答案 0 :(得分:0)
secs = long double(cur_time2 - cur_time1)/long double(CLOCKS_PER_SEC);
这是生成错误的行,类型转换的正确用法是:
secs = (long double)(cur_time2 - cur_time1)/(long double)CLOCKS_PER_SEC;