为什么STL头文件没有扩展名?

发布于 2024-07-20 07:57:10 字数 398 浏览 2 评论 0原文

我有这个基本的疑问。 STL 标头没有 .h 扩展名。

#include <vector>
#include <map>

这背后有什么具体原因吗? 谁知道这背后的历史,请分享。

编辑

@GMan 发现 迈克尔·伯尔的回答 这解决了这个问题。

I got this basic doubt.
The STL header doesn't have .h extension.

#include <vector>
#include <map>

Is there is any specific reason behind this? Anybody knows history behind this, please share.

EDIT:

@GMan found Michael Burr's answer
which addresses this question.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

星星的轨迹 2024-07-27 07:57:10
  • #include 指令不区分文件类型(它只是一个美化的复制粘贴操作) - 不会自动添加 .h 。
  • 提供的 C++ 标准头文件不带 .h 扩展名
  • 有时,供应商会提供向后兼容的头文件,其名称相同,但添加了 .h 扩展名

这一切都与命名空间有关。 C++ 标准头的 .h 对应项通常 #includes 正确的 C++ 标准头(不带 .h 扩展名),然后发出一堆使用(类似这样):

FILE: iostream.h

#include <iostream>

using std::iostream;
using std::ostream;
using std::ios;
...

而没有 .h 扩展名的头文件则不会用所有定义的类和类型污染命名空间。

  • The #include directive doesn't discriminate file types (it's just a glorified copy-paste operation) - no automatic adding of .h is happening.
  • C++ standard header files are provided without the .h extension
  • Sometimes backward compatibility header files are provided by the vendor with the same name with the .h extension added

It all has to do with namespaces. The .h counterparts for C++ standard headers usually #includes the proper C++ standard header (without .h extension) and then issues a bunch of using (something like this):

FILE: iostream.h

#include <iostream>

using std::iostream;
using std::ostream;
using std::ios;
...

whereas the headerfile without the .h extension does not pollute the namespace with all the defined classes and types.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文