#include <iostream.h> or <iostream>

J

John Tiger

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
 
O

Otto Barnes

John said:
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
 
V

Victor Bazarov

John Tiger said:
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
 
W

Wawa

#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.
 
J

John Harrison

Wawa said:
#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
 
W

Web Developer

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
 
K

Karl Heinz Buchegger

Web said:
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.
 
N

Noah Roberts

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.
 
V

Victor Bazarov

Noah Roberts said:
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
 
E

Evan

Web Developer said:
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?
 
G

ghl

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top