By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,505 Members | 1,761 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,505 IT Pros & Developers. It's quick & easy.

Confused with header declarations.........

AmberJain
Expert 100+
P: 884
Hello,

I had just started with C++ programming. I know that I will get answer to this question when I read "C++ Primer" book completely (in detail), but I thought that getting answer now is much better.

What is difference between using :
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
Expand|Select|Wrap|Line Numbers
  1. #include <iostream.h>
Bloodshed Dev c++ (MinGW compiler) reports a warning for second one as:

#warning : This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated.
What is the difference between two declarations?
Also, Which of above types should I prefer?


Thanks........
AmbrNewlearner
Nov 7 '08 #1
Share this Question
Share on Google+
9 Replies


boxfish
Expert 100+
P: 469
iostream.h is a deprecated header file. Dev-C++ gives a warning about it and MSVC++ gives an error. Don't use it if you can avoid it.
Nov 7 '08 #2

Expert 100+
P: 671
Letís see what a Google search gets you. Oh, plenty of results.

If you donít know how to Google, then itís a skill you will need to learn to be a programmer. If you know how to Google and you still choose to dump this question on us, then you are being outright lazy. It takes 10 seconds to Google. Not much effort there.
Nov 7 '08 #3

Banfa
Expert Mod 5K+
P: 8,916
iostream.h is what the file was called before C++ was standardised. The name of the file as specified in the standard is iostream. That is what was meant by

This file includes at least one deprecated or antiquated header.
iostream.h is deprecated.

The difference is that iostream encloses all its declarations in the std namespace which is generally considered to be best practice to avoid function/variable name clashes.

Generally if you are using a standards compliant compiler then you should prefer the form of the file without the .h for all C++ headers,including the C counter parts i.e. the C header math.h is cmath in C++.
Nov 7 '08 #4

weaknessforcats
Expert Mod 5K+
P: 9,197
You are supposed to use <iostream>.

<iostream.h> is a old C++ header that is pre-ANSI. That is, is was used for C++ before 1998.

One way to tell s that ANSI C++ header files have no extensions, like iostream. Those with .h extensions are C header files or those old C++ headers from before 1998.

All of the C headers have C++ equivalents. The C stdio.h is the C++ cstdio. The C++ name is just the C name with a leading c and the .h dropped.
Nov 7 '08 #5

100+
P: 424
There's a good reason why you shouldn't use <iostream.h>. Your C++ implementation may indeed store the header in a file called iostream.h on your hard drive but it doesn't have to. The compiler may use its knowledge of the standard library definition to optimize its implementation and simply make available the functions in a standard library header without including any header file.

As a side issue, in C you include headers from the C standard library using the .h extension, for example #include <stdio.h>. You can use the C standard library in C++ too, however, in you should then prefix the C library header name with the letter 'c' and drop the '.h' extension: #include <cstdio>. Although #include <stdio.h> will work as well, you shouldn't use this for the same reason as explained above, plus everything will be in the global namespace.

[EDIT: I posted this reply before seeing the others above... I think they pretty much covered it.]
Nov 7 '08 #6

100+
P: 424
By the way, I dont' really understand why so many C++ newbies seem to be using DevC++. It has bugs and hasn't been updated since 2005. VC++2008 Express or, if you prefer open source, Codeblocks, are much better free compilers for windows.
Nov 7 '08 #7

AmberJain
Expert 100+
P: 884
Let’s see what a Google search gets you. Oh, plenty of results.

If you don’t know how to Google, then it’s a skill you will need to learn to be a programmer. If you know how to Google and you still choose to dump this question on us, then you are being outright lazy. It takes 10 seconds to Google. Not much effort there.
Ah.....I should had searched google before posting this.

Google really helped me........
I will remember to search before posting next time.

Thanks......
AmbrNewlearner
Nov 7 '08 #8

AmberJain
Expert 100+
P: 884
Thanks Banfa, weaknessforcats, arnaudk, boxfish for your answers.......

@arnaudk : Dont worry.....I am using Dev C++ only because my linux crashed yesterday :(. I am trying to make my linux up and running soon. I use dev c++ only ocassionally when my linux crashes and I have to use windows. I would probably be back to gcc on linux tomorrow. And yes I will also try using codeblocks when I am on windows :)

Thanks.......
AmbrNewlearner
Nov 7 '08 #9

100+
P: 424
@arnaudk : Dont worry.....I am using Dev C++ only because my linux crashed yesterday :(. I am trying to make my linux up and running soon. I use dev c++ only ocassionally when my linux crashes and I have to use windows. I would probably be back to gcc on linux tomorrow. And yes I will also try using codeblocks when I am on windows :)
In that case codeblocks is ideal because it's a cross-platform IDE so you it in both windows and linux.
Nov 7 '08 #10

Post your reply

Sign in to post your reply or Sign up for a free account.