#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++ 程序中


基础教程推荐
- C/C++编程中const的使用详解 2023-03-26
- 详解c# Emit技术 2023-03-25
- C++详细实现完整图书管理功能 2023-04-04
- C语言基础全局变量与局部变量教程详解 2022-12-31
- C++使用easyX库实现三星环绕效果流程详解 2023-06-26
- 如何C++使用模板特化功能 2023-03-05
- C++中的atoi 函数简介 2023-01-05
- C语言 structural body结构体详解用法 2022-12-06
- C利用语言实现数据结构之队列 2022-11-22
- 一文带你了解C++中的字符替换方法 2023-07-20