这程序运行出错: 开始报错: std::sqrt(float) std::sqrt(long double)
//---------------------------------------------------------------------------
#include <iostream.h>
#include <conio.h>
#include <math.h>
#include <stdio.h>
#pragma hdrstop
#include <tchar.h>
//---------------------------------------------------------------------------
#pragma argsused
void getSqrRoot(char *buff, int x);
int _tmain(int argc, _TCHAR* argv[])
{
int x;
char buff[30];
cout << "Enter a number:";
cin >> x;
getSqrRoot(buff, x);
cout << buff << endl;
getch();
return 0;
} void getSqrRoot(char *buff, int x)
{
sprintf(buff, "The squar root is %f", sqrt(x));
}
//---------------------------------------------------------------------------
我开始以为是空间名using namespace std的问题。。。后来把x参数都int改成float型就好了
:我主要是想知道书上是c++builder6编译的能够运行吗?还是书上的习题错了?
:而且<stdio.h>也可有可无。。。
这些个东西怎么回事,sqrt()的传入参数不能自动转float吗?
//--------------------------------------------------------------------------- #include <iostream.h>
#include <conio.h>
#include <math.h>
//#include <stdio.h> #pragma hdrstop #include <tchar.h>
//--------------------------------------------------------------------------- #pragma argsused
void getSqrRoot(char *buff, float x);
int _tmain(int argc, _TCHAR* argv[])
{
float x;
char buff[30];
cout << "Enter a number:";
cin >> x;
getSqrRoot(buff, x);
cout << buff << endl;
getch();
return 0;
} void getSqrRoot(char *buff, float x)
{
sprintf(buff, "The squar root is %f", sqrt(x));
}
//---------------------------------------------------------------------------