why STL header files have no extension?

房东的猫 提交于 2019-12-21 08:05:09

问题


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.


回答1:


  • 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.



来源:https://stackoverflow.com/questions/901216/why-stl-header-files-have-no-extension

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!