Topic: #incluide <iostream>


Author: "Balog Pal" <pasa@lib.hu>
Date: Wed, 4 Feb 2009 10:40:47 CST
Raw View
I'm somewhat confused on standard-mandated effect <iostream> in intent,
theory and practice.

The synopsis section in the standard (27.3) just makes it declare cin,
cout,
and 6 other similar stream objects.

In the worls I see the practice to just #include <iostream> and start using
<< to those streams. Besides user code it is common in magazines and even
the standard text has examples.

I thought to access op << one must also #include <ostream>, defining them.
The above practice appear to work only because implementations happen to
include ostream from iostream, what is allowed but not necessary.

So my question is, whether including <ostream> is really needed in a
conforming program, or I overlooked some section and going without it is
actually fine.

In case of the former, the next question is if it were practical to adjust
the standard to this most common use -- or if not at least add the missing
includes to the code examples, and a note to the iostream section that
other
includes are still necessary.





--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: "Bo Persson" <bop@gmb.dk>
Date: Wed, 4 Feb 2009 15:08:35 CST
Raw View
Balog Pal wrote:
> I'm somewhat confused on standard-mandated effect <iostream> in
> intent, theory and practice.
>
> The synopsis section in the standard (27.3) just makes it declare
> cin, cout,
> and 6 other similar stream objects.
>
> In the worls I see the practice to just #include <iostream> and
> start using << to those streams. Besides user code it is common in
> magazines and even the standard text has examples.
>
> I thought to access op << one must also #include <ostream>,
> defining them. The above practice appear to work only because
> implementations happen to include ostream from iostream, what is
> allowed but not necessary.

Correct.

>
> So my question is, whether including <ostream> is really needed in a
> conforming program, or I overlooked some section and going without
> it is actually fine.

To be strictly conforming, yes.

It is possible to have an <iostream> header include only <iosfwd>, and
then declare 'extern ostream cout' etc.

>
> In case of the former, the next question is if it were practical to
> adjust the standard to this most common use

Already happened.  :-)

C++0x clearly states that it is enough to include <iostream> only. It
must include the other headers <ios>, <streambuf>, <istream>, and
<ostream>.


Bo Persson



--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]