#include <iostream.h> or <iostream>

Discussion in 'C++' started by John Tiger, Aug 4, 2003.

  1. John Tiger

    John Tiger Guest

    Can anybody have idea about the difference between #include
    <iostream.h> and
    #include <iostream>. Is later one valid statement on any compiler. I
    tried compiling on MSVC second statement give compilation error as
    #include expect filename.

    Anu help would be appreciated.

    thanx,
    John
    John Tiger, Aug 4, 2003
    #1
    1. Advertising

  2. John Tiger

    Otto Barnes Guest

    John Tiger wrote:
    > Can anybody have idea about the difference between #include
    > <iostream.h> and
    > #include <iostream>. Is later one valid statement on any compiler. I
    > tried compiling on MSVC second statement give compilation error as
    > #include expect filename.
    >
    > Anu help would be appreciated.
    >
    > thanx,
    > John


    For newer versions of gcc (3.x I think) iostream.h is deprecated. I've
    always used iostream.h when dealing with ms and mipspro.

    -Otto
    Otto Barnes, Aug 4, 2003
    #2
    1. Advertising

  3. "John Tiger" <> wrote...
    > Can anybody have idea about the difference between #include
    > <iostream.h> and
    > #include <iostream>. Is later one valid statement on any compiler. I
    > tried compiling on MSVC second statement give compilation error as
    > #include expect filename.


    <iostream> is a standard header where certain objects are declared.
    <iostream.h> is its obsolete incarnation, it has never been standard
    and existed in pre-standard era only.

    There is no requirement in the Standard that headers should exist in
    a file form.

    #include <iostream>

    is a standard way to incorporate the declarations of those certain
    objects into your code. It is valid on all compilers that are
    Standard-compliant.

    Questions on MSVC should be asked in microsoft.public.vc.language.
    It is quite possible that the version you have is too old to be at
    all compliant (released before the language was standardised, for
    example).

    Victor
    Victor Bazarov, Aug 4, 2003
    #3
  4. John Tiger

    Wawa Guest

    #include <iostream> is the Standard C++ way to include header files, the
    'iostream' is an identifier that maps to the file iostream.h. In older C++
    you had to specify the filename of the header file, hence #include
    <iostream.h>. Older compilers may not recognise the modern method, newer
    compilers will accept both methods but the old method is obsolete.

    iostream.h became iostream
    fstream.h becams fstream
    vector.h became vector
    string.h became sting etc.

    "John Tiger" <> wrote in message
    news:...
    > Can anybody have idea about the difference between #include
    > <iostream.h> and
    > #include <iostream>. Is later one valid statement on any compiler. I
    > tried compiling on MSVC second statement give compilation error as
    > #include expect filename.
    >
    > Anu help would be appreciated.
    >
    > thanx,
    > John
    Wawa, Aug 4, 2003
    #4
  5. "Wawa" <> wrote in message
    news:dmyXa.20409$...
    > #include <iostream> is the Standard C++ way to include header files, the
    > 'iostream' is an identifier that maps to the file iostream.h. In older

    C++
    > you had to specify the filename of the header file, hence #include
    > <iostream.h>. Older compilers may not recognise the modern method, newer
    > compilers will accept both methods but the old method is obsolete.
    >
    > iostream.h became iostream
    > fstream.h becams fstream
    > vector.h became vector
    > string.h became sting etc.
    >


    Not true.

    string and string.h are both standard header files that do completely
    different things.

    The other .h files are non-standard, it is not the case a compiler will
    accept both.

    john
    John Harrison, Aug 4, 2003
    #5

  6. > > #include <iostream> is the Standard C++ way to include header files, the
    > > 'iostream' is an identifier that maps to the file iostream.h. In older

    > C++
    > > you had to specify the filename of the header file, hence #include
    > > <iostream.h>. Older compilers may not recognise the modern method,

    newer
    > > compilers will accept both methods but the old method is obsolete.
    > >
    > > iostream.h became iostream
    > > fstream.h becams fstream
    > > vector.h became vector
    > > string.h became sting etc.
    > >

    >
    > Not true.
    >
    > string and string.h are both standard header files that do completely
    > different things.
    >
    > The other .h files are non-standard, it is not the case a compiler will
    > accept both.
    >
    > john


    I just like to add that the .h extension denotes a C header file, while the
    ..hpp extension denotes a C++ header file. Maybe someone can clarify this?.

    Side note: I assume a header file is like the import statement in Java?

    WD
    Web Developer, Aug 5, 2003
    #6
  7. Web Developer wrote:
    >
    > > > #include <iostream> is the Standard C++ way to include header files, the
    > > > 'iostream' is an identifier that maps to the file iostream.h. In older

    > > C++
    > > > you had to specify the filename of the header file, hence #include
    > > > <iostream.h>. Older compilers may not recognise the modern method,

    > newer
    > > > compilers will accept both methods but the old method is obsolete.
    > > >
    > > > iostream.h became iostream
    > > > fstream.h becams fstream
    > > > vector.h became vector
    > > > string.h became sting etc.
    > > >

    > >
    > > Not true.
    > >
    > > string and string.h are both standard header files that do completely
    > > different things.
    > >
    > > The other .h files are non-standard, it is not the case a compiler will
    > > accept both.
    > >
    > > john

    >
    > I just like to add that the .h extension denotes a C header file, while the
    > .hpp extension denotes a C++ header file. Maybe someone can clarify this?.
    >


    You need to understand that the extension is just a convention.

    Whatever filename you plug into

    #include "whatever"

    will be pulled in by the preprocessor.

    > Side note: I assume a header file is like the import statement in Java?


    It is an order to the preprocessor to replace the line containing #include
    with the actual content of the specified file. Nothing more, nothing less.

    --
    Karl Heinz Buchegger
    Karl Heinz Buchegger, Aug 5, 2003
    #7
  8. John Tiger

    Noah Roberts Guest


    >>string.h became sting etc.
    >>

    >
    >
    > Not true.
    >
    > string and string.h are both standard header files that do completely
    > different things.


    I thought that the current standard called string.h cstring to avoid
    ambiguity. "string.h" is a standard header file in C, but I didn't
    think it was supposed to be used by the C++ standard.

    >
    > The other .h files are non-standard, it is not the case a compiler will
    > accept both.
    >
    > john
    >
    >
    Noah Roberts, Aug 5, 2003
    #8
  9. "Noah Roberts" <> wrote...
    >
    > >>string.h became sting etc.
    > >>

    > >
    > >
    > > Not true.
    > >
    > > string and string.h are both standard header files that do completely
    > > different things.

    >
    > I thought that the current standard called string.h cstring to avoid
    > ambiguity. "string.h" is a standard header file in C, but I didn't
    > think it was supposed to be used by the C++ standard.


    It's used for compatibility reasons along with 17 other C headers.

    Victor
    Victor Bazarov, Aug 5, 2003
    #9
  10. John Tiger

    Evan Guest

    "Web Developer" <> wrote in message news:<>...
    > I just like to add that the .h extension denotes a C header file, while the
    > .hpp extension denotes a C++ header file. Maybe someone can clarify this?.


    This is convention, but you'll see a ton of headers with C++-only
    constructs in .h files as well. There are also other conventions that
    are less common; instead of .cpp sometimes .C (if you have a case
    sensitive filesystem) or .cxx or even .c++ if your filesystem supports
    that filename are used, and the corrosponding .H, .hxx, and .h++ are
    also occasionally seen.

    > Side note: I assume a header file is like the import statement in Java?


    They are somewhat similar, but there are significant differences.
    import only pulls some names into scope, for instance with an import
    javax.swing.* you'll only have to use the identifier JPanel instead of
    javax.swing.JPanel. In this sense it's like a using statement. (I
    chose "statement" to leave the exact meaning ambiguous; the above
    import is like a using directive, while if i had said import
    javax.swing.JPanel that's analogous to a using declaration.)

    #include <filename> and #include "filename" actually put the contents
    of filename into the current file. This is necessary because there is
    (thankfully IMO) no way of knowing where the compiler (or VW in the
    case of Java) should go to find things if I just write the following
    C++ file:

    int main () {
    std::cout << "Hello mars!\n";
    }

    It doesn't know about the namespace std or the object std::cout.
    Whereas if I write a similar Java program

    class neededClass {
    static int main() {
    System.out.writeln("Hello mars!\n");
    }
    }

    it knows where to find System, then System.out because of the standard
    naming scheme.

    Does that help?
    Evan, Aug 5, 2003
    #10
  11. John Tiger

    ghl Guest

    "Karl Heinz Buchegger" <> wrote in message
    news:...
    <<snip of good answer by Karl>>

    > > Side note: I assume a header file is like the import statement in Java?

    >
    > It is an order to the preprocessor to replace the line containing #include
    > with the actual content of the specified file. Nothing more, nothing less.


    And just to complete it: No, a header file is not like import statement in
    Java. import statement in Java is more like using.
    --
    Gary
    ghl, Aug 6, 2003
    #11
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ai@work
    Replies:
    9
    Views:
    528
    Ron Natalie
    Dec 16, 2004
  2. S. Nurbe

    iostream + iostream.h

    S. Nurbe, Jan 14, 2005, in forum: C++
    Replies:
    7
    Views:
    757
    red floyd
    Jan 15, 2005
  3. red floyd
    Replies:
    3
    Views:
    526
    Dietmar Kuehl
    Mar 8, 2005
  4. nichas
    Replies:
    9
    Views:
    333
    nichas
    Nov 28, 2005
  5. Andreas Bogenberger
    Replies:
    3
    Views:
    886
    Andreas Bogenberger
    Feb 22, 2008
Loading...

Share This Page