C++ math functions can be used without including the directive “math.h” in VS 2013

别等时光非礼了梦想. 提交于 2019-12-01 21:42:11

问题


I am very curious why I can use the math functions in C++ without including the "math.h". I can't find an answer with google search.

Here is the simple code I am executing. Everything is compiling and running.

#include <iostream>

using namespace std;

int main()
{
    const float PI = acosf(-1);
    cout << PI << endl;

    return 0;
}

回答1:


Any standard header is allowed to include any other standard header.




回答2:


if you would compile the same with gcc-4.8 it would complain.

Keep in mind that this is not something to rely on if you want your code to be portable and compilable on different versions of the same or different compilers.



来源:https://stackoverflow.com/questions/23308962/c-math-functions-can-be-used-without-including-the-directive-math-h-in-vs-20

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!