473,763 Members | 1,377 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1698
Rakesh wrote in news:3e******** *************** ***@posting.goo gle.com 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.1988 7$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************ *********@never box.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******* *************** ************@13 0.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************ *********@never box.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
360
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 not be used, instead it ought to be something like
3
1349
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 prototyoes of various functions. which file has the actual code of these functions?
3
1325
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 reference class in this namespace from a method in a class in the same namespace, the compiler makes me fully qualify the return type. It may have something to do with forward declarations or header inclusion order, because the small example I've...
77
4035
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 goto sometimes makes program some more cleaner and easy to understand and also quite useful (in error handling cases). So why goto is outlawed from civilized c programmers community. is there any technical inefficiency in that.
36
3362
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
1534
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 constant, and second pass the values in and out of functions? Here is the code; Thanks in advance:
3
1956
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 function, it could very well be done ny including a header file which specifies the function prototype...
2
1841
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 -pedantic-errors Wmissing-declarations -Wall -Werror -ansi mycode.c Well, then it responds with a warning message: gcc:Wmissing-declarations:No such file or directory.
9
1731
by: ramsatishv | last post by:
Hi, If I include a ".h" file for multiple times, will it increase my program size?? Regards Ram.
5
1587
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 correctly? For example: #include <stdio.h> int main(void) { int i;
0
9563
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9386
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9998
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9938
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9822
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7366
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6642
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
3
3523
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2793
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.