我应该使用哪个头文件而不是#include <bits stdc ++。h =“”>

时间:2017-10-18 16:23:01

标签: 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;

我想删除标头#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");
}

1 个答案:

答案 0 :(得分:10)

这类问题的解决方案是咨询相关功能的合适参考。一个备受推崇的C ++参考站点是cppreference.com。在这种情况下,其reference for modf以:

开头
  

在标题<cmath>

中定义

有你的答案。

将C ++标题<cmath>中定义的C ++版本(一系列重载函数)的上述参考与C标题<math.h>中定义的reference for the C version进行比较:

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版本。作为C ++的<cmath>声明了所有3 C ++重载(floatdoublelong double),其中你使用的是最后一个。

这实际上是要清除C标准库头文件(<*.h>)并使用C ++标准库文件库(<c*>)的原因之一。

相关问题