By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,264 Members | 1,761 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,264 IT Pros & Developers. It's quick & easy.

<fstream.h> , no need for <iostream.h>?

P: n/a
I have read that the inclusion of <fstream.h> makes the inclusion of
<iostream.h> unnecessary.

Is this correct?

Charles L
Jul 22 '05 #1
Share this Question
Share on Google+
11 Replies


P: n/a
"Charles L" <tj***@dodo.com.au> wrote in message
news:40******@news.comindico.com.au...
I have read that the inclusion of <fstream.h> makes the inclusion of
<iostream.h> unnecessary.

Is this correct?


First of all, don't use <fstream.h> and <iostream.h>. Use <fstream> and
<iostream> instead.

As for your question: I don't know if that behaviour is standard defined,
but on my system at least (VC7.1) including <fstream> does not make
inclusion of <iostream> unnecessary. So the answer is no.

--
Unforgiven

Jul 22 '05 #2

P: n/a
Unforgiven wrote:
"Charles L" <tj***@dodo.com.au> wrote in message
news:40******@news.comindico.com.au...
I have read that the inclusion of <fstream.h> makes the inclusion of
<iostream.h> unnecessary.

Is this correct?

First of all, don't use <fstream.h> and <iostream.h>. Use <fstream> and
<iostream> instead.

As for your question: I don't know if that behaviour is standard
defined, but on my system at least (VC7.1) including <fstream> does not
make inclusion of <iostream> unnecessary. So the answer is no.


The Standard mandates that different pieces are declared in different
headers. To use a certain element (class, template, object) one need
to include the corresponding header. It should be a simple rule to
follow, actually. You need 'cout' or 'cerr'? Use <iostream>. You
need 'string'? Use <string>. You need 'sort', use <algorithm>. Etc.

One should never concern oneself with (whether platform- or compiler-
dependent) cross-references between standard headers, even if there is
a logical connection between some of them which might suggest such
cross-reference (or inclusion of one into the other).

Victor
Jul 22 '05 #3

P: n/a
In article <2k************@uni-berlin.de>, Unforgiven wrote:
"Charles L" <tj***@dodo.com.au> wrote in message
news:40******@news.comindico.com.au...
I have read that the inclusion of <fstream.h> makes the inclusion of
<iostream.h> unnecessary.

Is this correct?


First of all, don't use <fstream.h> and <iostream.h>. Use <fstream> and
<iostream> instead.

As for your question: I don't know if that behaviour is standard defined,
but on my system at least (VC7.1) including <fstream> does not make
inclusion of <iostream> unnecessary. So the answer is no.

I'm taking a class in C++ and they use <iostream> rather than
<iostream.h> in the examples.

What is the reason for using one over the other. I know that if
you use the .h you don't have to use 'using std::xxxxxx' statements.

Jul 22 '05 #4

P: n/a
On Tue, 29 Jun 2004 14:15:29 -0500 in comp.lang.c++, Keith Meidling
<ke***@home.com> wrote,
I'm taking a class in C++ and they use <iostream> rather than
<iostream.h> in the examples.


<isotream> is part of ISO standard C++. <iostream.h> is not and never
has been. The only reason to use <iostream.h> any longer is in support
of ancient pre-standard code, and that will be painful with many
puzzling incompatibilities with the rest of the standard library. This
situation is AFAIK unique among the typical vendor's headers.

Probably best to go into your include directory and rename iostream.h
to legacy_iostream_do_not_use.h.

The other situation is headers inherited from C. In that case you can
probably choose <xxxxx.h> or <cxxxxx> without insurmountable problems.

Other standard C++ headers have no .h at all.

Jul 22 '05 #5

P: n/a
On Tue, 29 Jun 2004 21:11:50 GMT, David Harmon
<so****@netcom.com.invalid> wrote:
<isotream> is part of ISO standard C++.


<vbg>

Well, we all know what you meant to say ...

(now that's a hard typo to catch...)

--
Bob Hairgrove
No**********@Home.com
Jul 22 '05 #6

P: n/a
In message <sl******************@localhost.localdomain>, Keith Meidling
<ke***@home.com> writes
I'm taking a class in C++ and they use <iostream> rather than
<iostream.h> in the examples.

What is the reason for using one over the other. I know that if
you use the .h you don't have to use 'using std::xxxxxx' statements.

You make it sound like a penance ;-)
Having to use 'using std::xxx' (or prefix names with std::)
is a _good_ thing. Typing those few extra characters now may save you a
lot of work later.

--
Richard Herring
Jul 22 '05 #7

P: n/a
In article <DS**************@baesystems.com>, Richard Herring wrote:
In message <sl******************@localhost.localdomain>, Keith Meidling
<ke***@home.com> writes
I'm taking a class in C++ and they use <iostream> rather than
<iostream.h> in the examples.

What is the reason for using one over the other. I know that if
you use the .h you don't have to use 'using std::xxxxxx' statements.

You make it sound like a penance ;-)
Having to use 'using std::xxx' (or prefix names with std::)
is a _good_ thing. Typing those few extra characters now may save you a
lot of work later.


How would this save me work?

I don't want to sound like I'm questioning your statement, I'd just
like more info... If it's better to do it this way, hey, I'm all for it
I'd just like to know why to use one or the other...
Jul 22 '05 #8

P: n/a
In message <sl******************@localhost.localdomain>, Keith Meidling
<ke***@home.com> writes
In article <DS**************@baesystems.com>, Richard Herring wrote:
In message <sl******************@localhost.localdomain>, Keith Meidling
<ke***@home.com> writes
I'm taking a class in C++ and they use <iostream> rather than
<iostream.h> in the examples.

What is the reason for using one over the other. I know that if
you use the .h you don't have to use 'using std::xxxxxx' statements.

You make it sound like a penance ;-)
Having to use 'using std::xxx' (or prefix names with std::)
is a _good_ thing. Typing those few extra characters now may save you a
lot of work later.


How would this save me work?

I don't want to sound like I'm questioning your statement, I'd just
like more info... If it's better to do it this way, hey, I'm all for it
I'd just like to know why to use one or the other...


The technical term is "namespace pollution". The <*.h> headers dump
their contents into the global namespace; the ones without .h define
them in namespace std. With a big enough project, sooner or later
you're going to give one of your functions the same name as a standard
library function, or you'll use a third-party library which does so.
Using namespaces helps to prevent ambiguities.

More subtle, but sometimes more important, is the way the compiler looks
up functions depending on the type of their arguments and the namespace
in which they are defined.

--
Richard Herring
Jul 22 '05 #9

P: n/a
"Charles L" <tj***@dodo.com.au> wrote in message news:<40******@news.comindico.com.au>...
I have read that the inclusion of <fstream.h> makes the inclusion of
<iostream.h> unnecessary.

Is this correct?


Not at all. There exist no such Standard Headers. Here is a complete
list of Standard Headers, of which the last 18 are deprecated:

<algorithm> <iomanip> <list> <queue> <streambuf> <bitset> <ios>
<locale> <set> <string> <complex> <iosfwd> <map> <sstream> <typeinfo>
<deque> <iostream> <memory> <stack> <utility> <exception> <istream>
<new> <stdexcept> <valarray> <fstream> <iterator> <numeric>
<strstream> <vector> <cassert> <ciso646> <csetjmp> <cstdio> <ctime>
<cctype> <climits> <csignal> <cstdlib> <cwchar> <cerrno> <clocale>
<cstdarg> <cstring> <cwctype> <assert.h> <iso646.h> <setjmp.h>
<stdio.h> <wchar.h> <ctype.h> <limits.h> <signal.h> <stdlib.h>
<wctype.h> <errno.h> <locale.h> <stdarg.h> <string.h>

-- --
Abstraction is selective ignorance.
-Andrew Koenig
-- --
Jul 22 '05 #10

P: n/a
> I'm taking a class in C++ and they use <iostream> rather than
<iostream.h> in the examples.
There doesn't exist any Standard Header with the name <iostream.h>.

What is the reason for using one over the other. I know that if
you use the .h you don't have to use 'using std::xxxxxx' statements.


<iostream> exists. <iostream.h> doesn't exist.

-- --
Abstraction is selective ignorance.
-Andrew Koenig
-- --
Jul 22 '05 #11

P: n/a
>>>>What is the reason for using one over the other. I know that if
you use the .h you don't have to use 'using std::xxxxxx' statements.

You make it sound like a penance ;-)
Having to use 'using std::xxx' (or prefix names with std::)
is a _good_ thing. Typing those few extra characters now may save you a
lot of work later.
How would this save me work?

The technical term is "namespace pollution". The <*.h> headers dump
their contents into the global namespace; the ones without .h define
them in namespace std. With a big enough project, sooner or later
you're going to give one of your functions the same name as a standard
library function, or you'll use a third-party library which does so.
Using namespaces helps to prevent ambiguities.

More subtle, but sometimes more important, is the way the compiler looks
up functions depending on the type of their arguments and the namespace
in which they are defined.


Thanks for the information...
I'll start changing my code to reflect the std namespace.
Jul 22 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.