Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

<iostream> vs. <iostream.h> vs. "iostream.h"

Tags:

c++

iostream

When including a header file in C++, what's the difference between...

1) including the .h versus not including the .h when wrapping it in < > signs?

#include <iostream> vs. #include <iostream.h> 

2) wrapping the header name in double quotes versus wrapping it in < > signs?

#include <iostream.h> vs. #include "iostream.h" 

Thanks in advance!

like image 473
BeachRunnerFred Avatar asked Oct 18 '08 00:10

BeachRunnerFred


People also ask

Which is correct iostream or iostream H?

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.

What is the full form of iostream H?

iostream: iostream stands for standard input-output stream. This header file contains definitions of objects like cin, cout, cerr, etc.

What is #include iostream H?

So, #include is a preprocessor directive that tells the preprocessor to include header files in the program. < > indicate the start and end of the file name to be included. iostream is a header file that contains functions for input/output operations ( cin and cout ).


2 Answers

In short:

iostream.h is deprecated—it is the original Stroustrup version. iostream is the version from the standards committee. Generally, compilers point them both to the same thing, but some older compilers won't have the older one. In some odd cases, they will both exist and be different (to support legacy code) and you then must be specific.

"" versus <> simply means check the local directories for the header before going to the library (in most compilers).

like image 97
Adam Davis Avatar answered Oct 24 '22 03:10

Adam Davis


Here is a decent link article.

To summarize, the reason given:

The version of the iostream library that the Standards Committee produced was quite a bit different from the CFront implementation. {snip}

To ease transition, the C++ Standards Committee declared that code including the standard C++ headers would use include directives that lack an extension. This allowed compiler vendors to ship the old style C++ library headers with the .h extension and the new style headers without.

An advantage of not using the .h version:

There are several reasons why new code should be written using the extensionless version of the header files instead of the .h forms. The first is the unpredictability of such code when compiled on modern compilers. As previously mentioned, the result of using the .h headers is implementation specific. And as time goes by, the chance that a given compiler will have the old style library available decreases.

like image 25
Zee JollyRoger Avatar answered Oct 24 '22 02:10

Zee JollyRoger