iostream or iostream.h?

This is a discussion on iostream or iostream.h? within the C++ Programming forums, part of the General Programming Boards category; I see a lot of people talking about the differences between: #include <iostream> and #include <iostream.h> What are the differents ...

  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    32

    iostream or iostream.h?

    I see a lot of people talking about the differences between:
    #include <iostream>
    and
    #include <iostream.h>

    What are the differents and whats the correct choice and why?
    Thanks!

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    >> whats the correct choice

    iostream.

    along with one of the following:

    using namespace std;
    OR
    using std::cout;
    using std::cin;
    using std::endl;
    //etc. etc. ; with whatever else you are using

    OR

    std::cout << std::endl; //for example

    >>why?
    it's standard.

    check the faq, i think it may be there, not sure.

  3. #3
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    >>what are the differences

    in that library many, in others just an include of the old style header in namespace std.

    >>what is the correct choice

    providing your compiler is not too old then <iostream> is the correct choice. <iostream.h> is for backwards compatability with legacy code only.

    >>why?

    because the c++ standard says so. The old iostreams are deprecated.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  4. #4
    Burning in Hell! Luigi's Avatar
    Join Date
    Nov 2002
    Posts
    117
    <iostream>
    Is the new iso standard for c++ since 97 i think..
    so usually u better without the .h
    but there are few exceptions..
    like string and string.h
    if u want to use c string : include .h
    if u need c++ string : just <string>

    hope that helped..
    Also i think that question was in the faq..
    If not should be added..
    Luigi


    // I use Xcode 1.1 && CodeWarrior 8.3
    // When on Mac Os X 10.3.2

    // I use Microsoft Visual C++ 6.0
    // When on windows XP

  5. #5
    Registered User
    Join Date
    Apr 2003
    Posts
    32
    sorry the question wasn't in the FAQ.

  6. #6
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    "but there are few exceptions..
    like string and string.h
    if u want to use c string : include .h"


    Not true. You can do that, but it won't be according to the standard.

    #include<string> //for string objects

    #include<cstring> //for c-style string functions

    serruya,

    "sorry the question wasn't in the FAQ."

    See here:

    http://www.cplusplus.com/doc/ansi/hfiles.html
    Last edited by 7stud; 05-04-2003 at 03:40 PM.

  7. #7
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    "Bull$$$$! Actually check the standard before you attempt to use it to ``prove'' someone wrong!

    No thanks. My life doesn't hinge on the semantics of the standard.

  8. #8
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    Originally posted by 7stud
    "Bull$$$$! Actually check the standard before you attempt to use it to ``prove'' someone wrong!

    No thanks. My life doesn't hinge on the semantics of the standard.
    it can, won't necessarily, but can.

  9. #9
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    Really? So, if you follow the new standard for header files instead of the old deprecated method included for backwards compatability, you could actually die?

    lol

  10. #10
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    Originally posted by 7stud
    Really? So, if you follow the new standard instead of the old deprecated method included for backwards compatability, you could actually die?

    lol
    ooh, let's go for the sarcasm. I thought your statement was more based on, for example, work. Depending what you are coding, the standard can be relied upon.

    lol

  11. #11
    Registered User
    Join Date
    Feb 2003
    Posts
    28
    Greetings,

    The thing is, if you are using <iostream> you should use <cstring> if you are using the old C string routines. <string.h> is only in the standard for the same reason <iostream.h> is: backward compatibility! The old C/C++ style headers (*.h) are deprecated, which means that they may not be included in future versions of the standard.
    If you, vVv, had bothered to read the page you quoted, you'd notice at the very begginning this part:
    (Quote from the standard at: http://std.dkuug.dk/jtc1/sc22/wg21/d...depr.c.headers)
    1 This clause describes features of the C++ Standard that are specified
    for compatibility with existing implementations.

    2 These are deprecated features, where deprecated is defined as: Norma-
    tive for the current edition of the Standard, but not guaranteed to be
    part of the Standard in future revisions.

    (there's some points referencing some other deprecated features not relevant to this discussion right before the part you quoted, that i'll include below)

    1.5 Standard C library headers [depr.c.headers]

    1 For compatibility with the Standard C library, the C++ Standard
    library provides the 18 C headers, as shown in Table 1:

    Table 1--C Headers

    -----------------------------------------------------------------
    <assert.h> <iso646.h> <setjmp.h> <stdio.h> <wchar.h>
    <ctype.h> <limits.h> <signal.h> <stdlib.h> <wctype.h>
    <errno.h> <locale.h> <stdarg.h> <string.h>
    <float.h> <math.h> <stddef.h> <time.h>
    -----------------------------------------------------------------

    | |
    | |
    | |
    | |

    2 Each C header, whose name has the form name.h, behaves as if each name
    placed in the Standard library namespace by the corresponding cname
    header is also placed within the namespace scope of the namespace std
    and is followed by an explicit using-declaration (_namespace.udecl_)

    3 [Example: The header <cstdlib> provides its declarations and defini-
    tions within the namespace std. The header <stdlib.h> makes these
    available in the global name space, much as in the C Standard. --end
    example]
    So, in conclusion, <string.h> and all <*.h> headers are there for bacward compatibility and should no longer be used if you want to garantee that your code will be compilable in the future!
    And, always read before you quote!

  12. #12
    Registered User
    Join Date
    Feb 2003
    Posts
    28
    Greetings,

    In that case I'm sorry, but what I got from 7stud's post was not that <string.h> isn't there, but if you are coding C++ you should be using the Cname header instead, i.e: <cstring> and he is right.
    By the way, I made one mistake on my last post, <iostream.h> isn't even in the standard, some compilers support it, but the standard does not.

  13. #13
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    "I didn't advocate their use, either - What I did was show that 7stud's (rather implicit) claim that the string.h header is, according to the standard, not available anymore, is wrong."

    lol. Too bad your reading comprehension hasn't kept pace with your over inflated ego. Let's see if we can lead you through it step by step. Luigi cited the **new** standard for header files:

    "<iostream>
    Is the new iso standard for c++..."

    But Luigi said there were exceptions like <string.h>:

    "but there are few exceptions..
    like string and string.h"

    I pointed out that <string.h> wasn't an exception to the standard--the standard in discussion being the **new** standard:

    "You can do that, but it won't be according to the standard."

    at which point you threw a hissy fit. Whether you believe a statement like that is correct or not is irrelevant in light of your juvenile responses. The only thing you proved is how a spoiled child acts when he doesn't get his way. The previous posts made it adequately clear what the standard includes and doesn't include. Your contribution to this thread was nothing.

    I made no attempt to "prove" anything. I just pointed out to Luigi and possibly the original poster that instead of <string.h>, one should include <cstring> instead.

    Good day.
    Last edited by 7stud; 05-05-2003 at 08:09 AM.

  14. #14
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    "Bull$$$$! Actually check the standard before you attempt to use it to ``prove'' someone wrong!"

    "If you can't take constructive criticism, and have to resort to personal ``insults'', then don't post here!"

    lol. Your understanding of constructive criticism matches your level of reading comprehension.

    But back to the matter at hand: so you agree with Luigi that string and string.h are exceptions to the new standard? Also, in your world what other header files are exceptions to the new standard?
    Last edited by 7stud; 05-05-2003 at 08:35 AM.

  15. #15
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    While on the subject for header files, why are these 'new' standard headers extention-less? I checked my include folder, and both "iostream.h" and "iostream" (no extention) are there. Why didn't they name them "*.hh" or "StandardIostream.h" or something instead?
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. iostream.h (vs) iostream
    By Brain Cell in forum C++ Programming
    Replies: 5
    Last Post: 11-05-2004, 08:20 AM
  2. iostream vs iostream.h
    By LegendsEnd in forum C++ Programming
    Replies: 16
    Last Post: 03-27-2004, 07:14 PM
  3. Problem during compile (iostream.h error)
    By JoJo in forum C Programming
    Replies: 4
    Last Post: 04-29-2003, 07:58 PM
  4. Is there a user input command without using iostream.h?
    By Unregistered in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 11-04-2001, 02:15 AM
  5. << in iostream
    By badman in forum C++ Programming
    Replies: 8
    Last Post: 10-18-2001, 11:19 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21