C++ Tip : Should I use iostream.h or iostream?






4.75/5 (25 votes)
Minor edits to improve wording
Many C++ programmers still use
<iostream.h>
instead of the newer, standard compliant <iostream>
library. What are the differences between the two?
- The
.h
notation of standard header files was deprecated more than five years ago. Using deprecated features in new code is never a good idea. -
In terms of functionality,
<iostream>
contains a set of templatized I/O classes which support both narrow and wide characters, as opposed to<iostream.h>
which only supportschar
-oriented streams. - The C++ standard specification for iostream’s interface was changed, with many subtle aspects. Consequently, the interfaces and implementation of
<iostream>
differ from those of<iostream.h>
. <iostream>
components are declared in namespacestd
whereas<iostream.h>
components are in global scope (chances of name conflicts are greater).
<iostream>
header file, unless you are dealing with legacy code that is only compatible with <iostream.h>
. Otherwise, my suggestion is always to upgrade from the older version to newer version, which is quite easy to do.