谭浩强的C++,上面一个例子用VC2005编译不了,大家看看原因?

来源:百度知道 编辑:UC知道 时间:2024/05/18 08:48:35
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main()
{int m,k,i,n=0;
bool prime;
for(m=101;m<=200;m=m+2)
{prime=true;
k=int(sqrt(m));
for(i=2;i<=k;i++)
if(m%i==0) {prime=false;break;}
if (prime)
{cout<<setw(5)<<m;
n=n+1;
}
if(n%10==0) cout<<endl;
}
cout<<endl;
return 0;
}

k=int(sqrt(m));
改为
k=int(sqrt(double(m)));

在VC6.0上没有任何问题.我的VC2005没有装C++,只有C#,没法看,但确实没有问题.有可能是一些库文件更新了,但具体是哪个不清楚,你可以把问题发上来看看是哪里出错了.