Solved

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

Posted on 2004-11-01
1,203 Views
Last Modified: 2013-12-14
Sometimes we see

#include "iostream.h"

and other times we see

#include <iostream>

What is the difference?
0
Question by:baltmann
    5 Comments
     
    LVL 2

    Expert Comment

    by:pb_india
    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
    That's good. Could you elaborate more on "the legacy" and "the standard stuff" please.
    0
     
    LVL 9

    Assisted Solution

    by:zaghaghi
    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:
    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
    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
    I will show you how to create a ASP.NET Captcha control without using any HTTP HANDELRS or what so ever. you can easily plug it into your web pages. For Example a = 2 + 3 (where 2 and 3 are 2 random numbers) Session("Answer") = 5 then we…
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
    The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

    934 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

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now