Archived

This topic is now archived and is closed to further replies.

<iostream.h> Vs <iostream>

This topic is 5382 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

whats the difference between the two, other than having to add ''using namespace std;'' ?? _________________________________________ "Why, why why does everyone ask ''''why'''' when ''''how'''' is so much more fun" -Spawn 1997

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
<iostream.h> will include the whole library while <iostream>
just makes the library available to use. In order to actually
use functions in iostream you must declare which ones you are
going to use with "using namespace std::xxx". The actual difference in the way the program runs is negligable but it is a good programming practice to know what comes from which libraries and it is more professional to code in this manner.

Share this post


Link to post
Share on other sites
quote:
Original post by Anonymous Poster
will include the whole library while
just makes the library available to use. In order to actually
use functions in iostream you must declare which ones you are
going to use with "using namespace std::xxx". The actual difference in the way the program runs is negligable but it is a good programming practice to know what comes from which libraries and it is more professional to code in this manner.

Uhm... uh... what?





"If there is a God, he is a malign thug."
-- Mark Twain

Share this post


Link to post
Share on other sites
<iostream> and <iostream.h> are likely to include much the same things, where they are both present. This is not the issue.

The fact of the matter is that <iostream.h> represents an ad-hoc standard before the actual C++ standard was established. As such, many compilers ship with this file for compatibility with legacy code, but the standard only requires <iostream> to be present. As such, a fully compliant and excellent compiler might very well lack <iostream.h>. If this file is included, there are no guarantees as to what it contains or how it operates. <iostream> is guaranteed to be present on any standard compliant compiler, and its contents are similarly standardised. The same applies to the other standard headers (<fstream>/<fstream.h>, <cctype>/<ctype.h>, etc.).

Share this post


Link to post
Share on other sites
quote:
Original post by Anonymous Poster
will include the whole library while
just makes the library available to use. In order to actually
use functions in iostream you must declare which ones you are
going to use with "using namespace std::xxx". The actual difference in the way the program runs is negligable but it is a good programming practice to know what comes from which libraries and it is more professional to code in this manner.


You mean the right thing but you are using very wrong terms

iostream.h doesn't use namespaces, because it's from an old C++ standart (backward compatibility) where namespaces weren't implemented

#include <iostream.h>

will do exactly the same as

#include <iostream>
using namespace std;

("using namespace std" isn't good coding style and should be avoided)

[edited by - noVum on March 23, 2003 2:22:45 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by noVum
#include <iostream.h>

will do exactly the same as

#include <iostream>


No, it won''t. In some implementations, this may be the case, but in general you have absolutely no guarantees at all as to the contents of the iostream.h header.





"If there is a God, he is a malign thug."
-- Mark Twain

Share this post


Link to post
Share on other sites
Exactly. iostream.h is deprecated and may not necessarily have standard (correct) behavior. You technically have no guarantee that calling cout from iostream.h won't format your hard drive.

[edited by - micepick on March 23, 2003 2:36:48 PM]

Share this post


Link to post
Share on other sites
From the offizial C++ standart (ISO/IEC 14882:1998(E) -- C++)

quote:

-7- depr.c.headers, Standard C library headers, describes the effects of using the name.h (C header) form in a C++ program.*

[Footnote: The ".h" headers dump all their names into the global namespace, whereas the newer forms keep their names in namespace std. Therefore, the newer forms are the preferred forms for all uses except for C++ programs which are intended to be strictly compatible with C. --- end foonote]



The .h headers are left in the standart for backward compatibility, so it WILL do exactly the same on every standart conforming compiler

Share this post


Link to post
Share on other sites
In summary: Use <iostream>, don't use <iostream.h>.

This forum is named 'For Beginners' and not 'By Beginners'.



Update GameDev.net system time campaign - success at last

[edited by - dalleboy on March 24, 2003 10:51:05 AM]

Share this post


Link to post
Share on other sites
quote:

From the offizial C++ standart (ISO/IEC 14882:1998(E) -- C++)

...

The .h headers are left in the standart for backward compatibility, so it WILL do exactly the same on every standart conforming compiler


I believe the standard is talking about C headers (that is, cstdlib vs. stdlib.h), not "pre-C++" headers like iostream.h. The way I read it, iostream.h is not guaranteed to be present and contain the correct stuff, because it''s not a C header.

Share this post


Link to post
Share on other sites
quote:
Original post by noVum
From the offizial C++ standart (ISO/IEC 14882:1998(E) -- C++)



-7- depr.c.headers, Standard C library headers, describes the effects of using the name.h (C header) form in a C++ program.*

[Footnote: The ".h" headers dump all their names into the global namespace, whereas the newer forms keep their names in namespace std. Therefore, the newer forms are the preferred forms for all uses except for C++ programs which are intended to be strictly compatible with C. --- end foonote]



The .h headers are left in the standart for backward compatibility, so it WILL do exactly the same on every standart conforming compiler


Read more carefully. This clause refers to Standard C headers. The old C++ classes in iostream.h most certainly aren''t part of the C library. What this says is that a C header name.h becomes cname. So, following that logic, iostream.h would have become ciostream...

The clause doesn''t apply. iostream.h contains the original iostream library (which was already around by 1991), while iostream contains the standard iostream library (finalized in the 1998 standard).

The C++ Standard does not even mention iostream.h. Not even to say that it is deprecated. As far as ISO C++ is concerned iostream.h doesn''t exist.

Some differences between the two (from "Standard C++ IOStreams and Locales" by Langer & Kreft )

  • The standard IOStreams is a template taking the character type as a parameter.
  • The base class ios is split into character-type-dependent and character-type-independent portions.
  • Standard IOStreams optionally throws exceptions.
  • Standard IOStreams is internationalized.
  • Assignment and copying of streams are prohibited.
  • File descriptors are no longer supported.
  • The character-array-based strstreams are replaced by string-based streams.
  • Additional virtual functions have been added to the stream buffer interface.


Obsolete programmers, books and teachers still use and teach iostream.h. Forum posters put their foot in their mouth... and we keep repeating over and over again to those confused people to not use it.

Hopefully, 20 years from now, the issue will either be moot or finally solved.


[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]

Share this post


Link to post
Share on other sites
quote:
Original post by Fruny
Hopefully, 20 years from now, the issue will either be moot or finally solved.

<my_bad_humor>By then we are using C<<1 instead for C++... </my_bad_humor>



Update GameDev.net system time campaign - success at last

Share this post


Link to post
Share on other sites