C++ header | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

C++ header

Why are c++ header files included without extension .h???Does all C++ support without .h extension?If not mention the header files which do not support it

18th Aug 2018, 2:21 PM
Jesha Rose George
Jesha Rose George - avatar
2 Answers
+ 3
For custom headers (headers you created) you still need to specify as #include "your_header.h", but for standard include files you specify the name only, omitting the file extension is the standard, as I recall from a previous thread I read. Also for headers inherited from C, a prefix of "c" is prepended to the file name e.g. stdio.h -> cstdio, stdlib.h -> cstdlib Hth, cmiiw
18th Aug 2018, 4:57 PM
Ipang
+ 2
When the C preprocessor encounters an #include declaration it copies all of the target file contents into your file. It generally doesn't take into account stuff like file extensions or anything like that. You suffix your header files ".h" so you know what they are. The C++ standard library doesn't follow this rule because stuff like "string.h" and "iostream.h" would have broken many existing projects.
18th Aug 2018, 2:51 PM
Vlad Serbu
Vlad Serbu - avatar