65.9K
CodeProject is changing. Read more.
Home

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

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.75/5 (25 votes)

Jun 28, 2010

CPOL
viewsIcon

56961

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 supports char-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 namespace std whereas <iostream.h> components are in global scope (chances of name conflicts are greater).
For these reasons, you should never mix the two libraries in one program. As a rule of thumb, use the newer <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.