Kar*_*a K 1 c++ type-conversion include header-files
#include <iostream>
#include <string>
#include <sstream>
//#include <bits/stdc++.h>
#include <iomanip> // std::setprecision
#include <math.h>
using namespace std;
Run Code Online (Sandbox Code Playgroud)
我想删除标题#include <bits/stdc++.h>,因为它显着减慢了我的编译时间.
当我删除它时,我收到以下错误:
error: cannot convert ‘long double*’ to ‘double*’ for argument ‘2’ to ‘double modf(double, double*)’
fractpart = modf(val, &intpart);
Run Code Online (Sandbox Code Playgroud)
我认为问题是缺少头文件,但不知道它是哪一个.
我得到错误的代码是:
fractpart = modf(val, &intpart);
if (fractpart != 0) {
throw Error("ERR");
}
Run Code Online (Sandbox Code Playgroud)
Rei*_*ica 10
这类问题的解决方案是咨询相关功能的合适参考.一个备受推崇的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 );
Run Code Online (Sandbox Code Playgroud)
C没有函数重载,所以modf在<math.h>只有double版本.<cmath>,是C++,声明所有的3个C++重载(float,double,long double),其中您使用的最后一个.
这实际上是保持C标准库头文件(<*.h>)并使用C++标准库文件()的原因之一<c*>.