某段程序,VC2005编译不过,但VC2008就能编译的过
程序的目的是寻找到三边都小于五百的毕达哥拉斯三角。其中的pow函数。我也写了cmath头文件,但是还是会出现一堆错误,比如说:errorC2732:linkagespec...
程序的目的是寻找到三边都小于五百的毕达哥拉斯三角。其中的pow函数。我也写了cmath头文件,但是还是会出现一堆错误,比如说:
error C2732: linkage specification contradicts earlier specification for 'pow'
1> e:\program files (x86)\microsoft visual studio 8\vc\include\math.h(489) : see declaration of 'pow'
1>e:\program files (x86)\microsoft visual studio 8\vc\include\math.h(490) : warning C4244: 'argument' : conversion from 'double' to 'int', possible loss of data
1>e:\program files (x86)\microsoft visual studio 8\vc\include\math.h(526) : error C2556: 'float pow(double,double)' : overloaded function differs only by return type from 'double pow(double,double)'
1> e:\program files (x86)\microsoft visual studio 8\vc\include\math.h(123) : see declaration of 'pow'
1>e:\program files (x86)\microsoft visual studio 8\vc\include\math.h(526) : error C2371: 'pow' : redefinition; different basic types
1> e:\program files (x86)\microsoft visual studio 8\vc\include\math.h(123) : see declaration of 'pow'
1>e:\program files (x86)\microsoft visual studio 8\vc\include\math.h(526) : warning C4244: 'argument' : conversion from 'double' to 'float', possible loss of data
1>e:\program files (x86)\microsoft visual studio 8\vc\include\math.h(526) : warning C4244: 'argument' : conversion from 'double' to 'float', possible loss of data
但是在VC2008里面编译就很顺利。
莫非是我的cmath函数库出问题了= =?肿么把它设置回来…………
程序代码如下:
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
int main()
{
cout<<"Side1"<<setw(10)<<"Side2"<<setw(10)<<"Hypotenuse"<<endl;
double hypotenuse;
int counter=0;
for(double Side1=1; Side1<=500; Side1++)
{
for(double Side2=1; Side2<=500; Side2++)
{
hypotenuse=pow((Side2*Side2+Side1*Side1),0.5);
if ((hypotenuse==(int)hypotenuse) && hypotenuse<500)
{
++counter;
cout<<Side1<<setw(4)<<Side2<<setw(4)<<hypotenuse<<endl;
}
}
}
cout<<"A total of "<<counter<<" triples were found"<<endl;
return 0;
} 展开
error C2732: linkage specification contradicts earlier specification for 'pow'
1> e:\program files (x86)\microsoft visual studio 8\vc\include\math.h(489) : see declaration of 'pow'
1>e:\program files (x86)\microsoft visual studio 8\vc\include\math.h(490) : warning C4244: 'argument' : conversion from 'double' to 'int', possible loss of data
1>e:\program files (x86)\microsoft visual studio 8\vc\include\math.h(526) : error C2556: 'float pow(double,double)' : overloaded function differs only by return type from 'double pow(double,double)'
1> e:\program files (x86)\microsoft visual studio 8\vc\include\math.h(123) : see declaration of 'pow'
1>e:\program files (x86)\microsoft visual studio 8\vc\include\math.h(526) : error C2371: 'pow' : redefinition; different basic types
1> e:\program files (x86)\microsoft visual studio 8\vc\include\math.h(123) : see declaration of 'pow'
1>e:\program files (x86)\microsoft visual studio 8\vc\include\math.h(526) : warning C4244: 'argument' : conversion from 'double' to 'float', possible loss of data
1>e:\program files (x86)\microsoft visual studio 8\vc\include\math.h(526) : warning C4244: 'argument' : conversion from 'double' to 'float', possible loss of data
但是在VC2008里面编译就很顺利。
莫非是我的cmath函数库出问题了= =?肿么把它设置回来…………
程序代码如下:
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
int main()
{
cout<<"Side1"<<setw(10)<<"Side2"<<setw(10)<<"Hypotenuse"<<endl;
double hypotenuse;
int counter=0;
for(double Side1=1; Side1<=500; Side1++)
{
for(double Side2=1; Side2<=500; Side2++)
{
hypotenuse=pow((Side2*Side2+Side1*Side1),0.5);
if ((hypotenuse==(int)hypotenuse) && hypotenuse<500)
{
++counter;
cout<<Side1<<setw(4)<<Side2<<setw(4)<<hypotenuse<<endl;
}
}
}
cout<<"A total of "<<counter<<" triples were found"<<endl;
return 0;
} 展开
2个回答
2011-11-27
展开全部
修改了一处,VC6编译运行可以通过。见注释
================================================
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
int main()
{
cout<<"Side1"<<setw(10)<<"Side2"<<setw(10)<<"Hypotenuse"<<endl;
double hypotenuse;
int counter=0;
for(double Side1=1; Side1<=500; Side1++)
{
for(double Side2=1; Side2<=500; Side2++)
{
hypotenuse=pow((Side2*Side2+Side1*Side1),0.5);
if ((hypotenuse==(int)hypotenuse) && hypotenuse<500)
{
++counter;
cout<<Side1<<setw(4)<<Side2<<setw(4) <<hypotenuse<<endl;//括号问题。setw(4)应该为setw(4)
}
}
}
cout<<"A total of "<<counter<<" triples were found"<<endl;
return 0;
}
================================================
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
int main()
{
cout<<"Side1"<<setw(10)<<"Side2"<<setw(10)<<"Hypotenuse"<<endl;
double hypotenuse;
int counter=0;
for(double Side1=1; Side1<=500; Side1++)
{
for(double Side2=1; Side2<=500; Side2++)
{
hypotenuse=pow((Side2*Side2+Side1*Side1),0.5);
if ((hypotenuse==(int)hypotenuse) && hypotenuse<500)
{
++counter;
cout<<Side1<<setw(4)<<Side2<<setw(4) <<hypotenuse<<endl;//括号问题。setw(4)应该为setw(4)
}
}
}
cout<<"A total of "<<counter<<" triples were found"<<endl;
return 0;
}
追问
虽然您说的是对的……这段放到VC2005还是会报错。但放到2008里编译就通过了……所以我想说我的VC2005是哪里出问题了……
追答
楼主,我用VS2005又试了下,可以正常编译运行,是不是你的VS2005有问题啊,建议重装下。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询