Clarification regarding #include declarations.

R

Rakesh

Hi,
I was writing this C++ program wherein I used an include statement
like -


#include <iostream.h>

I was told by my co-worker that this form of including a file is
deprecated and should not be used, instead it ought to be something
like

#include <iostream>

And this ought to be the standard way of including files.
So does this imply that , my program should not have any header files
of the following type , something like -


#include <myclassdef.h>

...

is that deprecated / alternate syntax of #include that achieves the
same thing.

- Rakesh
 
R

Rolf Magnus

Rakesh said:
Hi,
I was writing this C++ program wherein I used an include statement
like -


#include <iostream.h>

I was told by my co-worker that this form of including a file is
deprecated and should not be used,

In standard C++, it is not just deprecated, but even never existed. The
<iostream.h> header predates the C++ standard, but is still supported
(but deprecated) on some compilers so you can still use legacy code.
For new code you shouldn't use it.
instead it ought to be something
like

#include <iostream>

And this ought to be the standard way of including files.

Not "the standard way of including files". <iostream> simply is the name
of a header that is part of the standard said:
So does this imply that , my program should not have any header files
of the following type , something like -


#include <myclassdef.h>

...

is that deprecated / alternate syntax of #include that achieves the
same thing.

No. From the C++ view, you can name your headers as you like. Some
development environments might even force you to use a name that ends
in .h or somehting similar. However, the headers that are part of the
C++ standard (like <iostream> or <string> or <vector>) all don't end
in .h, with the exception of the C standard headers. They are available
both in <stdio.h> form and in <cstdio> form.
 
K

Kevin Goodsell

Rakesh said:
Hi,
I was writing this C++ program wherein I used an include statement
like -


#include <iostream.h>

I was told by my co-worker that this form of including a file is
deprecated and should not be used, instead it ought to be something
like

#include <iostream>

These two use exactly the same form of the #include directive. It is not
deprecated, it is the standard, modern way to include a standard header.
However, only the latter #include actually refers to a standard header.
The former is not deprecated, it has never been standard.
And this ought to be the standard way of including files.
So does this imply that , my program should not have any header files
of the following type , something like -


#include <myclassdef.h>

Usually you don't use the #include <file> syntax for your own
project-wide header files. You should probably use #include "file"
instead. The standard doesn't have much to say about the differences
between these two forms, but by convention this is the way it is done.
...

is that deprecated / alternate syntax of #include that achieves the
same thing.

There is no deprecated #include syntax. The fact that <iostream.h> is
not standard does not affect how you use your own header files.

-Kevin
 

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,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top