What's the difference between #include "iostream.h" and #include <iostream>?

Sometimes we see

#include "iostream.h"

and other times we see

#include <iostream>

What is the difference?
baltmannAsked:
Who is Participating?
 
pb_indiaConnect With a Mentor Commented:
iostream.h> is pre-standard C++, so it's 'old fashioned'.

<iostream> is standard C++, in which the standard library is in namespace std.

If you use the latter (which you ought to if your compiler supports it) then you'll need to qualify entities from the standard library in one of the following ways:

[1] using directive:

using namespace std;

[2] using declaration:

using std::cout;
using std::endl;

[3] namespace prefix:

std::cout << "hello world" << std::endl;

0
 
pb_indiaCommented:
If you write #include <iostream.h> you get the legacy.
 If you write #include <iostream>"you get the standard stuff.
 If you write #include "iostream.h" - searches for the file in subdirectories on your system.

Normally for iostream you would not use "iostream.h"
0
 
baltmannAuthor Commented:
That's good. Could you elaborate more on "the legacy" and "the standard stuff" please.
0
 
Hamed ZaghaghiConnect With a Mentor ProgrammerCommented:
Hi,

before 1999, this include is true that use the header name with .h, that in some compiler like VC++ 6 works, but after 1999 in ANSI startndard this include and other standard includes, must use with out .h and must use "using namespace std;" to use these standard headers.

like this:
#include "iostream"

using namespace std;

have a good including day;
0
 
pb_indiaCommented:
Also,
using .h is C style. in C++ you should use <iostream>
Historically, <iostream.h> and similar header files are older than <iostream>. What happened is that early version of C++ provided a library, and header files such as <iostream.h> declared the various classes, operations, etc.

During the process of producing the C++ standard, a lot of features were added to the language. Such as exceptions, namespaces, the bool type, etc etc. Language features associated with templates were also radically improved. One consequence of that was that those developing the standard realised that the existing "standard" library was clunky compared with the language itself. So, the libraries were revamped. The STL was designed, and then attention was focused on basic things such as I/O. One of the core decisions was that things should be put into a specific namespace if at all possible, and the std namespace came into existance. When it was pointed out that this would mean a problem keeping backward compatibility with older C++ code (that used iostream.h, etc), it was realised that a different set of #include <> names were needed. What it boiled down to was that everything in the C++ standard library (streams, the STL, etc) were placed in header files without a .h extension, and a new set of header files to provide C library functions (prefixed with c, such as <cstdio>) to allow for the fact that C standards would evolve independently, but allow a particular set of accepted C functions to be frozen in C++.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.