使用#include< filename>和#include< filename.h>在C ++? [英] What is the difference between using #include<filename> and #include<filename.h> in C++?

查看:177
本文介绍了使用#include< filename>和#include< filename.h>在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标准继承的文件变为 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 ,而 filename.h 中的名称位于全局命名空间范围内。所以你会在cstddef中找到stddef.h中的 :: size_t 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 ++编译器的兼容性


  • 名称位于命名空间 std :: 中。没有名称冲突了。

  • 新的C ++功能(例如float,long的重载数学函数)

  • 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天全站免登陆