473,387 Members | 1,318 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Clarification regarding #include declarations.

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
Jul 22 '05 #1
7 1665
Rakesh wrote in news:3e**************************@posting.google.c om in
comp.lang.c++:
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
Its not deprecated, deprecated means something that was/is standard
that will nolonger be standard at some point in the future.

There never was a *standard* header <iostream.h>.

#include <iostream>
This is part of the standard library, and is what you should use.

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>

No, this should be:

#include "myclassdef.h"

Only use the <> syntax for header's that come with your implementation
(aka compiler), including the headers that are part of the Standard
library.

Also, what file extension you give *your* files is up to you, .h, .hpp
and .hxx are common. Some OS's allow your files to be assosiated with
a particular application based on the files extension (an editor say)
so you should probably use one if these.
...

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


The headers <stdio.h> etc, inhereted from C are *deprecated*, you should
use <cstdio> etc, instead, which only supply the standard library in
namespace std:

Depricate this:

#include <stdio.h>
int main()
{
printf( "Helow world\n" );
}

Code like this:

#include <cstdio>
int main()
{
std::printf( "Helow world\n" );
}

HTH.

Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jul 22 '05 #2
Rob Williscroft wrote:

Depricate this:

#include <stdio.h>
int main()
{
printf( "Helow world\n" );
}

Code like this:

#include <cstdio>
int main()
{
std::printf( "Helow world\n" );
}


Personally I'd deprecate any use of printf/scanf-related functions.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.
Jul 22 '05 #3
Kevin Goodsell wrote in news:v_zgc.19887$A_4.14887
@newsread1.news.pas.earthlink.net in comp.lang.c++:
Rob Williscroft wrote:

Depricate this:

#include <stdio.h>
int main()
{
printf( "Helow world\n" );
}

Code like this:

#include <cstdio>
int main()
{
std::printf( "Helow world\n" );
}


Personally I'd deprecate any use of printf/scanf-related functions.


Well I've never used scanf, so I really don't care,
remove it, depricate it, enhance it, I'll never notice :).

printf can be safe, gcc has been doing this for years and I
got the impression from a recient comp.lang.c x-post that
many in the C world consider this to be something that
should be expected from a a High Quality(tm) implementation.

In the next standard we may get templates function's with
an unlimited number of arguments (an equivalent of , ...),
so we may be able to fix the "type saftey" problem with
std::printf().

Even better we can write:

template < typename T, template Args ... >
std::shared_ptr< T > std::shared_new( Args );

template < typename T, template Args ... >
std::auto_ptr< T > std::auto_new( Args );

and can depricate new and delete :). (*)

Rob.
--
*) Only /half/ joking.
Jul 22 '05 #4
Rob Williscroft wrote:

printf can be safe, gcc has been doing this for years and I
got the impression from a recient comp.lang.c x-post that
many in the C world consider this to be something that
should be expected from a a High Quality(tm) implementation.
GCC's printf() (and scanf()) format checking is cool, but it's not a
general solution. It can't possibly check all formats, because formats
are not necessarily known at compile time. We don't see a lot of
run-time generated format strings, but it's the only way to do some
things (unless you drop printf()/scanf() completely and roll your own,
which isn't necessarily a bad idea). The obvious example, I think, is a
%s or %[ scanf() format where the corresponding char array argument is
dynamically allocated, or of unknown (at compile-time) size for other
reasons, such as being the argument to a function.

I can't think of an obvious printf() example -- field widths can be
specified with a variable in printf() -- so maybe the situation isn't as
bad there. Of course, even if it's not *necessary* to use dynamic format
strings for a particular situation, that doesn't mean somebody won't use
them.

In the next standard we may get templates function's with
an unlimited number of arguments (an equivalent of , ...),
so we may be able to fix the "type saftey" problem with
std::printf().


Overloading + chaining (overloading being the key part, chaining is just
for convenience), like in the standard streams, seems like the "right"
solution to me. I don't know about this.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.
Jul 22 '05 #5
Kevin Goodsell <us*********************@neverbox.com> wrote in message > >
Code like this:

#include <cstdio>
int main()
{
std::printf( "Helow world\n" );
}


Thanks for letting me know a different syntax.
Personally I'd deprecate any use of printf/scanf-related functions.


I am a little bit confused here. You mean to say, they are not
supposed to be used ( is it that we should use only - cin , cout or
something similar to that).

- Rakesh.
Jul 22 '05 #6
Rob Williscroft <rt*@freenet.co.uk> wrote in message news:<Xn**********************************@130.133 .1.4>...

Depricate this:

#include <stdio.h>
int main()
{
printf( "Helow world\n" );
}

Code like this:

#include <cstdio>
int main()
{
std::printf( "Helow world\n" );
}


Thanks for letting me know that, Rob.

- Rakesh.
Jul 22 '05 #7
Rakesh wrote:
Kevin Goodsell <us*********************@neverbox.com> wrote in message > >

Personally I'd deprecate any use of printf/scanf-related functions.

I am a little bit confused here. You mean to say, they are not
supposed to be used ( is it that we should use only - cin , cout or
something similar to that).


I'm saying that I would recommend not using them. They are very
difficult to use correctly, and your compiler probably won't tell you
when you use them wrong.

Anything that defeats type-checking is best avoided, particularly when
better options are available (such as standard streams classes).

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.
Jul 22 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Rakesh | last post by:
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...
3
by: siddharth_jain_1 | last post by:
Hello, 1) what do header files contain exactly? Do they just contain the variable declarations, typedefs and function prototypes? 2) taking the example of iostream.h: it contains the...
3
by: John Ratliff | last post by:
I have a program, the classes that belong to it all belong to a special namespace I created for them. This had lead to a minor issue I don't quite understand. For some reason, when I return a...
77
by: M.B | last post by:
Guys, Need some of your opinion on an oft beaten track We have an option of using "goto" in C language, but most testbooks (even K&R) advice against use of it. My personal experience was that...
36
by: Viken Karaguesian | last post by:
Hello all, I just need confirmation on the subject of font size and its inheritance. Take this example: body { font-family: arial; font-size: 95%; }
7
by: James | last post by:
Hello, First off, I know this code will not compile and am not asking for someone to solve it for me. What I am asking is from the code below, how does one first define an array as a...
3
by: sam_cit | last post by:
Hi Everyone, I have seen in some project where functions are declared as extern, what is the possible reason to do this? To my best understanding, if some other file wan't to invoke this...
2
by: mattmao | last post by:
My code works fine with this command: gcc mycode.c It is compiled and runs just as I wanted. But since my assignment has a specific restriction, my code must go through this: gcc...
9
by: ramsatishv | last post by:
Hi, If I include a ".h" file for multiple times, will it increase my program size?? Regards Ram.
5
by: Philip Potter | last post by:
I have a somewhat flippant question regarding undefined behaviour. Does an operation which invokes undefined behaviour affect the whole program, or are earlier statements guaranteed to execute...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.