#include <cmath>与#include <math.h>在 C++ 程序中 [英] #include <cmath> vs #include <math.h> in a C++ program

查看:44
本文介绍了#include <cmath>与#include <math.h>在 C++ 程序中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

What are the considerations for including the former rather than the latter in a C++ program? I always include math.h, stdlib.h and never cmath, cstdlib etc. I don't understand the reason the latter even exist, could someone please enlighten me?

解决方案

Prefer to include the <c ...> headers. They are C++ standard library headers. The <... .h> headers are headers defined by the C standard library:

The C++ standard library also makes available the facilities of the C standard library, suitably adjusted to ensure static type safety.

The C++ headers, for the most part, have content identical to the corresponding C library headers except that the names are all defined in the std namespace.

Except as noted in Clauses 18 through 30 and Annex D, the contents of each header cname shall be the same as that of the corresponding header name.h, as specified in the C standard library (1.2) or the C Unicode TR, as appropriate, as if by inclusion. In the C++ standard library, however, the declarations (except for names which are defined as macros in C) are within namespace scope (3.3.6) of the namespace std. It is unspecified whether these names are first declared within the global namespace scope and are then injected into namespace std by explicit using-declarations

这篇关于#include &lt;cmath&gt;与#include &lt;math.h&gt;在 C++ 程序中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆