What is the difference between iostream.h and iostream | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

What is the difference between iostream.h and iostream

28th Jan 2017, 6:33 AM
Sanjana Khowal
Sanjana Khowal - avatar
2 Answers
+ 9
Why doesn’t iostream have a .h extension? Another commonly asked question is “why doesn’t iostream (or any of the other standard library header files) have a .h extension?”. The answer is, because iostream.h is a different header file than iostream is! To explain requires a very short history lesson. When C++ was first created, all of the files in the standard runtime library ended in .h. Life was consistent, and it was good. The original version of cout and cin lived in iostream.h. When the language was standardized by the ANSI committee, they decided to move all of the functions in the runtime library into the std namespace (which is generally a good idea). However, this presented a problem: if they moved all the functions into the std namespace, none of the old programs would work any more! To try to get around this issue and provide backwards compatibility for older programs, a new set of header files was introduced that use the same names but lack the .h extension. These new header files have all their functionality inside the std namespace. This way, older programs that include #include <iostream.h> do not need to be rewritten, and newer programs can #include <iostream>. When you include a header file from the standard library, make sure you use the non .h version if it exists. Otherwise you will be using a deprecated version of the header that is no longer supported. In addition, many of the libraries inherited from C that were still useful in C++ were given a c prefix (e.g. stdlib.h became cstdlib). The functionality from these libraries was also moved into the std namespace to help avoid naming collisions. However, when you write your own header files, you should give them all a .h extension, since you will not be putting your code in the std namespace. Rule: use the non .h version of a library if it exists, and access the functionality through the std namespace. If the non .h version does not exist, or you are creating your own headers, use the .h version
5th Feb 2017, 4:44 AM
BARBIE ZAVERI
BARBIE ZAVERI - avatar
+ 4
In c++ it is okay not to write( .h ) extension after any header file and if you would like to insert(.h) extension after the header file , then also compiler will allow that.
29th Jan 2017, 5:40 AM
BARBIE ZAVERI
BARBIE ZAVERI - avatar