#包括LT&;&CMATH GT; VS的#include&LT;&math.h中GT;在C ++程序 [英] #include <cmath> vs #include <math.h> in a C++ program
问题描述
什么是包括前而不是在C ++程序后者的考虑?我总是包括文件math.h
,文件stdlib.h
从不 CMATH
, cstdlib
等等。我不明白,后者甚至存在的原因,可能有人请赐教?
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包含 c为C ...&GT;
头。他们是C ++标准库头。在&LT; ... .H&GT;
头是由C标准库定义的头文件:
Prefer to include the <c ...>
headers. They are C++ standard library headers. The <... .h>
headers are headers defined by the C standard library:
C ++标准库也使得现有的C标准库的设施,适当的调整,以保证静态类型安全。
The C++ standard library also makes available the facilities of the C standard library, suitably adjusted to ensure static type safety.
C ++的头文件,在大多数情况下,有内容等同于相应的C库头除了名字都在 STD
命名空间中定义。
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.
除了通过30和附件D的第18所指出的,每一个标题的内容 CNAME
应是相同相应的头的 name.h
,如C标准库(1.2)或中联code TR酌情指定的,仿佛被列入。在C ++标准库,但是,声明(除了被定义为C宏的名字)是空间std的命名空间范围(3.3.6)之内。它是不确定是否这些名称全局命名空间范围内的第一个声明,然后由明确的使用,声明注入空间std
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 headername.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
这篇关于#包括LT&;&CMATH GT; VS的#include&LT;&math.h中GT;在C ++程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!