使用#include< filename>之间的区别和#include< filename.h>在C ++中 [英] Difference between using #include<filename> and #include<filename.h> in C++
问题描述
使用 #include< filename>之间的区别和 C ++ 中的#include< filename.h
> ?使用了哪两个?为什么使用它?
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 ++只包含C标准中找不到的文件使用 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 Standard继承的文件变为 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中定义为宏的名称可在<$ c中的命名空间 std ::
中找到$ c> cfilename 在C ++中,而 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 ++中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!