14

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.

Community
  • 1
  • 1
aJ.
  • 34,624
  • 22
  • 86
  • 128
  • 3
    Duplicate: http://stackoverflow.com/questions/441568/when-can-you-omit-the-file-extension-in-an-include-directive – GManNickG May 23 '09 at 09:42
  • Thanks @GMan. My search in SO and Google didn't reveal this. That is because the question linked is bit different. Anyway I feel Michael Burr's answer addresses my question. – aJ. May 23 '09 at 09:50

1 Answers1

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

Anders Hansson
  • 3,746
  • 3
  • 28
  • 27