c++ 编译出错原因新手求教
[C++ Error] Unit1.cpp(8): E2015 Ambiguity between 'std::sqrt(double)' and 'std::sqrt(long double)'
源码:
#include<iostream>
#include<cmath>
using namespace std;
void main()
{
float sum=0;
for(int i=1;i<=10;i++)
sum+=sqrt(i);
cout<<"sum="<<sum<<endl;
}
为什么会出现这个问题
[解决办法]
新建个控制台程序(console wizard),souce type 选 c++ ,
在unit1.cpp中清空,贴上下面代码运行
#include <iostream>
#include <cmath>
#include "stdio.h"
#pragma hdrstop
using namespace std;
#pragma argsused
int main(int argc, char* argv[])
{
float sum = 0;
for (int i=1; i<=10; i++)
sum += sqrt((double)i);
cout << "sum = " << sum << endl;
system("pause");
return 0;
}