使用 #include<filename> 的区别和#include<filename.h>在 C++ 中 [英] Difference between using #include<filename> and #include<filename.h> in C++

查看:34
本文介绍了使用 #include<filename> 的区别和#include<filename.h>在 C++ 中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 #include 有什么区别?和 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&lt;filename&gt; 的区别和#include&lt;filename.h&gt;在 C++ 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆