1

i know we always include a header files, then why do i find some header files like

#include<iostream>

with no .h extension but some header files like

#include<windows.h>

with the .h extension and i also tried to add.h to some header files like iostream.h but that didnt work, so what's the difference between adding a .h extension when includeing a file andnot doing this.

thanks for all replies... much appreciated

user3407319
  • 227
  • 2
  • 10
  • it didn't work because `iostream.h` didn't exist on you system. There is no difference. – gongzhitaao Mar 12 '14 at 15:39
  • 1
    You need to give the exact name of the file. The standard C++ headers do not have a `.h` in the filename. However, there is a file `windows.h`. If you create your own header files, you can name them however you like, but ending them with `.h` is normal convention. – BoBTFish Mar 12 '14 at 15:39
  • "Why do some names end in y and others in ie? If I write Jimmy instead of Jimmie, then I get no matches." – Raymond Chen Mar 12 '14 at 15:46

3 Answers3

5

It simply depends on the particular header.

The standard library headers (like <iostream>) do not have an extension - just use the name.

For other header files (strictly formally, these shouldn't be called "headers," but "included source files"), it's whatever the file's author decided to use. So windows.h uses extension .h. Boost prefers .hpp on its files. .hh or .hxx is also commonly used for C++, but if the header file's author decides to use myHeader.IamBob, you will have to:

#include <myHeader.IamBob>
Angew is no longer proud of SO
  • 167,307
  • 17
  • 350
  • 455
1

You always need to specify the exact file name. There is no "implicit" .h. For a standard conforming implementation, the c++ libraries have no extension.

Therefore

#include <iostream>

is valid and conforming, while

#include <iostream.h>

may be accepted by your compiler (or your neighbours), but it isn't portable nor is it guaranteed to be identical or compatible with iostream.

stefan
  • 10,215
  • 4
  • 49
  • 90
  • 1
    *And* it's entirely possible that `` will resolve to something different than `` (that was the case with VC 6, for example). The ``-style headers were pre-standard implementations, with a slightly different interface. – Angew is no longer proud of SO Mar 12 '14 at 15:51
0

The iostream.h header used to be common before C++ was first standardized in 1998. But since the 98 standard used instead of , the latter has fallen out of favor (being non-standard and all) and is no longer supported on all platforms. Code that uses it should be considered non-standard legacy code and is not portable. include <iostream>, not <iostream.h> (the latter is deprecated)

kvivek
  • 3,321
  • 1
  • 15
  • 17