#include lt;cmathgt; vs #include lt;math.hgt; in a C++ program(#include lt;cmathgt;与#include lt;math.hgt;在 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 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
这篇关于#include <cmath>与#include <math.h>在 C++ 程序中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:#include <cmath>与#include <math.h>在 C++ 程序中
- ubuntu下C/C++获取剩余内存 2023-09-18
- Easyx实现扫雷游戏 2023-02-06
- c++ const 成员函数,返回一个 const 指针.但是返回的指针是什么类型的 const? 2022-10-11
- C语言手把手带你掌握带头双向循环链表 2023-04-03
- 详解C语言中sizeof如何在自定义函数中正常工作 2023-04-09
- C语言qsort()函数的使用方法详解 2023-04-26
- C语言详解float类型在内存中的存储方式 2023-03-27
- Qt计时器使用方法详解 2023-05-30
- 我应该为我的项目使用相对包含路径,还是将包含目录放在包含路径上? 2022-10-30
- C++ 数据结构超详细讲解顺序表 2023-03-25