Difference between using #includelt;filenamegt; and #includelt;filename.hgt; in C++(使用 #includelt;filenamegt; 的区别和#includelt;filename.hgt;在 C++ 中)
问题描述
使用 #include
What is the difference between using #include<filename> and #include<filename.h
> in C++? Which of the two is used and why is it is used?
推荐答案
C++ only include-files not found in the C standard never used filename.h
.自从第一个 C++ 标准问世(1998 年)以来,他们就使用 filename
作为自己的标头.
C++ only include-files not found in the C standard never used filename.h
. Since the very first C++ Standard came out (1998) they have used filename
for their own headers.
由 C 标准继承的文件变为 cfilename
而不是 filename.h
.像 filename.h
这样继承使用的 C 文件已被弃用,但仍是 C++ 标准的一部分.
Files inherited by the C Standard became cfilename
instead of filename.h
. The C files inherited used like filename.h
are deprecated, but still part of the C++ standard.
不同之处在于,在 C++ 中未定义为宏的名称位于命名空间 std::
中的 cfilename
中,而名称位于 filename.h
在全局命名空间范围内.所以你会在 stddef.h 中找到 ::size_t
,在 cstddef 中找到 std::size_t
.两者都是标准 C++,但不推荐使用 ::size_t(参见 C++ 标准的附录 D).
The difference is that names not defined as macros in C are found within namespace std::
in cfilename
in C++, while names in filename.h
are within the global namespace scope. So you will find ::size_t
in stddef.h, and std::size_t
in cstddef. Both are Standard C++, but use of ::size_t is deprecated (See Annex D of the C++ Standard).
这就是区别.
- 与 C 编译器的兼容性
- 与非常古老的 C++ 编译器的兼容性
- 名称在命名空间
std::
中.不再有名称冲突. - 新的 C++ 功能(例如浮点、长整数的重载数学函数)
- C 兼容性标头 (
filename.h
) 将来可能会消失.
- Names are within namespace
std::
. No name-clashes anymore. - New C++ features (e.g. overloaded math functions for float, long)
- C Compatibility Headers (
filename.h
) could disappear in future.
这篇关于使用 #include<filename> 的区别和#include<filename.h>在 C++ 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 #include<filename> 的区别和#include<filename.h>在 C++ 中


- 从python回调到c++的选项 2022-11-16
- 与 int by int 相比,为什么执行 float by float 矩阵乘法更快? 2021-01-01
- 近似搜索的工作原理 2021-01-01
- STL 中有 dereference_iterator 吗? 2022-01-01
- 如何对自定义类的向量使用std::find()? 2022-11-07
- C++ 协变模板 2021-01-01
- Stroustrup 的 Simple_window.h 2022-01-01
- 一起使用 MPI 和 OpenCV 时出现分段错误 2022-01-01
- 静态初始化顺序失败 2022-01-01
- 使用/clr 时出现 LNK2022 错误 2022-01-01