为什么STL头文件没有扩展名? [英] why STL header files have no extension?

查看:53
本文介绍了为什么STL头文件没有扩展名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

编辑:

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

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

推荐答案

  • #include 指令不区分文件类型(它只是一种美化的复制粘贴操作)- 不会自动添加 .h.
  • C++ 标准头文件不带 .h 扩展名
  • 有时供应商会提供向后兼容的头文件,名称相同但添加了 .h 扩展名
  • 这一切都与命名空间有关.C++ 标准头文件的 .h 对应物通常 #includes 正确的 C++ 标准头文件(没有 .h 扩展名),然后发出一堆 using(类似这样):

    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):

    文件:iostream.h

    FILE: iostream.h

    #include <iostream>
    
    using std::iostream;
    using std::ostream;
    using std::ios;
    ...
    

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

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

    这篇关于为什么STL头文件没有扩展名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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