Support Forums

Full Version: #include <example.(h?)>
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Why do some people do #include <stdio.h> for example, not just #include <stdio>?

I don't understand -_-
Because you need to include the actual name of the file, but some of the standard library is available with or without the .h extension. Your own header files will likely always have a .h extension, so you will need to include them as MyHeaderFile.h and not just MyHeaderFile.
its a good idea to always put the .h on the end. i think that goes with most like windows.h and iosteam.h
I think it depends on the compiler is that correct?
The compiler won't care what the file is called as long as it can find it, you could call it MyHeader.holyshitlions if you wanted and providing you told the compiler what it was, it wouldn't care.

The lack of a .h extension simply comes form the various versions of the C and C++ standards and backwards compatibility between them.
(07-29-2010, 07:49 PM)mmki Wrote: [ -> ]its a good idea to always put the .h on the end. i think that goes with most like windows.h and iosteam.h
I think it depends on the compiler is that correct?

When it comes to standard C headers, they always end with the .h extension. If you ever see them called without the extension then the programmer is writing non portable, malformed code.

For standard C++ headers, however, there is no file extension. The files iostream.h and iostream are entirely different. Once upon a time the C++ headers had file extensions. But then C++ was standardized and the file extensions were dropped. Thus iostream.h is the old header and will contain now-obsolete code.