Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
#include <example.(h?)>
#1
Why do some people do #include <stdio.h> for example, not just #include <stdio>?

I don't understand -_-
Reply
#2
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.
[Image: sig.php]
The little boat gently drifted across the pond exactly the way a bowling ball wouldn't.
Reply
#3
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?
[Image: blanktemplate.png]
Reply
#4
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.
[Image: sig.php]
The little boat gently drifted across the pond exactly the way a bowling ball wouldn't.
Reply
#5
(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.
Ho, ho, ho! Well, if it isn't fat stinking billy goat Billy Boy in poison!
How art thou, thou globby bottle of cheap, stinking chip oil?
Come and get one in the yarbles, if ya have any yarbles, you eunuch jelly thou!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  c++ include error (geany) Socrates 4 1,610 10-28-2009, 01:41 PM
Last Post: TheDoctor

Forum Jump:


Users browsing this thread: 1 Guest(s)