Topic: newbie Q: #include
Author: Francis Glassborow <francis@robinton.demon.co.uk>
Date: 1999/08/19 Raw View
In article <37ba15a2.639509@news.airmail.net>, William H. Bloodworth
<whbloodworth@usa.net> writes
>All of the "new" C++ standard headers do not have the ".h" extension. The
>new C++ headers have the same information as the old (or explicitly
>#include the old one) but their declarations are placed in the "std"
>namespace. This is why you have to use "using namespace std;" when using
>the new-style headers.
No, I believe that there are quite a few other differences between the
de facto classic standard (i.e. not a standard as such) iostream.h and
the final standard iostream.
Francis Glassborow Journal Editor, Association of C & C++ Users
64 Southfield Rd
Oxford OX4 1PA +44(0)1865 246490
All opinions are mine and do not represent those of any organisation
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: clamage@eng.sun.com (Steve Clamage)
Date: 1999/08/19 Raw View
whbloodworth@usa.net (William H. Bloodworth) writes:
>On 17 Aug 99 11:52:22 GMT, "cayuse" <cayuse@geocities.com> wrote:
>> I am very curious about this: #include<iostream> and
>>#include<iostream.h>
>>what exactly the difference between these two includes? The only thing I
>>know is if I use #include<iostream>, I need to add the "using namespace std"
>>otherwise I need to put std::cout instead of just cout. There should be
>>something more besides this, right?
>All of the "new" C++ standard headers do not have the ".h" extension. The
>new C++ headers have the same information as the old (or explicitly
>#include the old one) but their declarations are placed in the "std"
>namespace.
It sounds like you are mixing up two distinct situations.
The 18 headers defined by the C standard (<stdlib.h>, <stdio.h>,
<assert.h>, <ctype.h>, etc) are part of the C++ standard, and can
be used in standard-conforming programs in the same way as they
could in pre-standard C++.
Each of those 18 headers (e.g., <stdio.h>, <ctype.h>) also exists in
a form without the trailing .h and with a leading c (<cstdio>, <cctype>).
In those headers, the declarations from the corresponding .h header
appear only in namespace std.
In the .h form of the headers, the declaration are accessibles both
in namespace std and in the global namespace.
But the question was about the iostream headers, which are not
part of the C standard, and which do not fall under that rule.
The standard does not mention <iostream.h>, but only <iostream>.
Like all the C++ specific headers, the declarations in <iostream>
appear only in namespace std.
An implementation might choose to provide a header <iostream.h>,
but if it does, the standard has nothing to say about its contents.
Implementations in fact differ in exactly what you get if you
include <iostream.h>. (Sun C++ provides two different versions
of <iostream.h>, corresponding to two different iostream
libraries -- "classic" and "standard".)
>This is why you have to use "using namespace std;" when using
>the new-style headers.
No, you don't have to do that. You can provide a using-declaration
for individual items if you like. Example:
#include <iostream>
using std::cout;
using std::endl;
int main()
{
cout << "Hello, world" << endl;
}
>It is also advantageous to use the new-style header files for the old C
>headers which have been renamed. For example, instead of
> #include <stdio.h>
>use
> #include <cstdio>
I don't find that advantageous for real-world programs.
The C headers are the subject of several different standards.
In addition to the C and C++ standards, the POSIX and X/Open standards
specify their contents. Beyond that, those headers have
traditionally contained other platform-specific declarations.
C++ implementors who wish to support multiple standards and
maintain compatibility can simply make the standard C++ declarations
available in namespace std, leaving the rest of the contents
alone. Existing programs using the .h headers work unchanged.
(A "strict conformance" mode of the compiler would disable the
extra declarations.)
But what about the new form of the headers (e.g. <cstdio>)?
Should they contain declarations not described by the C or C++
headers? Those headers are not mentioned by any other standard,
nor is there any legacy issue because they are new. Implementations
can vary in that regard. As a programmer, you cannot depend on any
contents beyond what the C and C++ standards describe.
For example, if I'm on a Unix platform, I can depend on including
<stdio.h> and having access to the "fileno" function. But if I
include <cstdio> I cannot depend on it being present.
--
Steve Clamage, stephen.clamage@sun.com
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: "Gene Bushuyev" <gbush@synopsys.com>
Date: 1999/08/18 Raw View
The standard specifies only <iostream> name. Before standard came into being
the <iostream.h> was widely use. Compiler vendors still supply <iostream.h>
for compatibility purposes. I looked at Rogue Wave <iostream.h> and it
basically #includes <istream>, <ostream> and "using namespace std" Since the
later defeats the use of std namespace, I would suggest you never use
<iostream.h> unless necessary.
Gene Bushuyev
cayuse wrote in message ...
>Hi,
> I am very curious about this: #include<iostream> and
>#include<iostream.h>
>what exactly the difference between these two includes? The only thing I
>know is if I use #include<iostream>, I need to add the "using namespace
std"
>otherwise I need to put std::cout instead of just cout. There should be
>something more besides this, right?
>---
>[ comp.std.c++ is moderated. To submit articles, try just posting with ]
>[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
>[ --- Please see the FAQ before posting. --- ]
>[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: whbloodworth@usa.net (William H. Bloodworth)
Date: 1999/08/18 Raw View
On 17 Aug 99 11:52:22 GMT, "cayuse" <cayuse@geocities.com> wrote:
>Hi,
> I am very curious about this: #include<iostream> and
>#include<iostream.h>
>what exactly the difference between these two includes? The only thing I
>know is if I use #include<iostream>, I need to add the "using namespace std"
>otherwise I need to put std::cout instead of just cout. There should be
>something more besides this, right?
All of the "new" C++ standard headers do not have the ".h" extension. The
new C++ headers have the same information as the old (or explicitly
#include the old one) but their declarations are placed in the "std"
namespace. This is why you have to use "using namespace std;" when using
the new-style headers.
Also notice that you may add "items" to a namespace in several different
files/locations such as this:
namespace CustomNS
{
class Foo {};
class Foo2 {};
};
namespace CustomNS
{
class Foo3 {};
};
Now, all three Foo classes are contained in the CustomNS namespace. This
is a great language feature that provides a way for large-scale C++
projects to prevent identifier clashes...as long as you use good namespace
names.
It is also advantageous to use the new-style header files for the old C
headers which have been renamed. For example, instead of
#include <stdio.h>
use
#include <cstdio>
I believe the convention is to drop the file extension and add a 'c' to the
front of the filename.
William Bloodworth
=====================================================================
= Great Achievement REQUIRES Great Effort.
=
= William H. Bloodworth - whbloodworth@usa."net" ICQ: 21901934
=====================================================================
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: "cayuse" <cayuse@geocities.com>
Date: 1999/08/17 Raw View
Hi,
I am very curious about this: #include<iostream> and
#include<iostream.h>
what exactly the difference between these two includes? The only thing I
know is if I use #include<iostream>, I need to add the "using namespace std"
otherwise I need to put std::cout instead of just cout. There should be
something more besides this, right?
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]