#include <iostream>
#include <string>
#include <sstream>
//#include <bits/stdc++.h>
#include <iomanip> // std::setprecision
#include <math.h>
using namespace std;
我想删除标头#include <bits/stdc++.h>
,因为它会大大减慢我的编译时间。
删除它时,出现以下错误:
error: cannot convert ‘long double*’ to ‘double*’ for argument ‘2’ to ‘double modf(double, double*)’
fractpart = modf(val, &intpart);
我认为问题在于缺少头文件,但不知道它是哪一个。
我得到错误的代码是:
fractpart = modf(val, &intpart);
if (fractpart != 0) {
throw Error("ERR");
}
此类问题的解决方案是针对所讨论的功能咨询适当的参考。一个广受好评的C ++参考站点是cppreference.com。在这种情况下,其参考modf
始于:
在标头中定义
<cmath>
有你的答案。
比较在C ++头定义的C ++版本(一个家庭的重载函数)将上述参考<cmath>
与为C版本参考在C头限定<math.h>
:
float modff( float arg, float* iptr );
double modf( double arg, double* iptr );
long double modfl( long double arg, long double* iptr );
C没有函数重载,所以modf
在<math.h>
只有double
版本。<cmath>
,是C ++,声明所有的3 C ++重载(float
,double
,long double
),其中您使用的最后一个。
这实际上是避免使用C标准库标头(<*.h>
)和使用C ++标准库标头()的原因之一<c*>
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句