What is the difference between iostream
and iostream.h
?
3 Answers
iostream.h
is deprecated by those compilers that provide it, iostream
is part of the C++ standard.
To clarify explicitly there is no mention of iostream.h
at all in the current C++ standard (INCITS ISO IEC 14882 2003).
Edit: As @Jerry mentioned, not only does the current standard not mention it, but no standard for C++ mentions it.

- 339,232
- 124
- 596
- 636
-
You should probably mention the std namespace. – zdan Jun 04 '10 at 17:47
-
@Jerry: Kept the wording but clarified the meaning – Brian R. Bondy Jun 04 '10 at 17:49
-
The ORIGINAL meaning of the iostream.h include was that it preserves backwards compatibility with code written before namespaces were widely used in C++. – Warren P Mar 09 '13 at 18:08
-
2Is this answer a difference between iostream.h and iostream? I don't think so. – stackOverflow Oct 29 '14 at 12:21
iostream is a standard header. iostream.h is a non-standard header that was very common in pre-standard C++, and is what iostream evolved from. It's still common to have iostream.h around, presumably for use with older programs.
If your implementation have a working copy of iostream.h, it is probably the same as iostream except that everything in iostream is in the std
namespace, while iostream.h generally preceded namespaces, and didn't use them.
If your implementation has both iostream and iostream.h, iostream is likely to work like:
namespace std
{
#include <iostream.h>
}
although that's not necessarily how it's written.

- 56,304
- 9
- 91
- 158
-
1Actually, there's often a *lot* more difference than that -- the streams in iostream.h typically weren't templates like they are in iostream. If you do much beyond simple reading and writing (e.g., write any manipulators) the difference is often substantial. – Jerry Coffin Jun 04 '10 at 18:22
-
@Jerry: You're right, but unfortunately you're bringing back memories of a system I had to convert that had some ill-documented wizardry done on the streams. However, that doesn't necessarily mean there's a significant difference between iostream.h and iostream in a modern implementation. If I remember, I'll look at my gcc implementation when I get home. – David Thornley Jun 04 '10 at 18:37
-
1yes, that why I commented elsewhere that the differences between iostream and iostream.h vary widely. In some, iostream.h is a current implementation, with `using` declarations for all the contents. In other cases, it's an old implementation (and in a few, something in between...) – Jerry Coffin Jun 04 '10 at 19:05
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, while maintaining backward 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
Source: https://www.learncpp.com/cpp-tutorial/19-header-files/

- 1
- 1

- 609
- 6
- 10