[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2004-11-01
5
Medium Priority
?
1,457 Views
Last Modified: 2013-12-14
Sometimes we see

#include "iostream.h"

and other times we see

#include <iostream>

What is the difference?
0
Comment
Question by:baltmann
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 2

Expert Comment

by:pb_india
ID: 12464729
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
 

Author Comment

by:baltmann
ID: 12464836
That's good. Could you elaborate more on "the legacy" and "the standard stuff" please.
0
 
LVL 9

Assisted Solution

by:zaghaghi
zaghaghi earned 80 total points
ID: 12465010
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
 
LVL 2

Accepted Solution

by:
pb_india earned 720 total points
ID: 12465678
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
 
LVL 2

Expert Comment

by:pb_india
ID: 12465700
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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question