.h or namespace std

This is a discussion on .h or namespace std within the C++ Programming forums, part of the General Programming Boards category; Why is one not "supposed" to use #include <iostream.h> or #include <whatever.h>? What benefit does #include <iostream> using namespace std ...

  1. #1
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136

    .h or namespace std

    Why is one not "supposed" to use #include <iostream.h> or #include <whatever.h>? What benefit does #include <iostream> using namespace std have?

  2. #2
    UNBANNED OneStiffRod's Avatar
    Join Date
    Jan 2002
    Posts
    669
    the #includes with the .h extension are the old C headers, the <iostream> is the new C++ headers.
    My Avatar says: "Stay in School"

    Rocco is the Boy!
    "SHUT YOUR LIPS..."

  3. #3
    Hamster without a wheel iain's Avatar
    Join Date
    Aug 2001
    Posts
    1,385
    so

    <iostream>
    <conio>
    using namespace std;

    is the same as using the include directives for the same files, doesnt the names space setup an area to do with variables or something.
    Monday - what a way to spend a seventh of your life

  4. #4
    Registered User
    Join Date
    Dec 2001
    Posts
    28
    Originally posted by iain
    so

    <iostream>
    <conio>
    using namespace std;

    is the same as using the include directives for the same files, doesnt the names space setup an area to do with variables or something.
    Including a header file like iostream.h has the same effect -- it imports all the variables/functions in the header file to the program's global namespace.

  5. #5
    UNBANNED OneStiffRod's Avatar
    Join Date
    Jan 2002
    Posts
    669
    My understanding is that the .h has been removed from the STD headers only (standard C++ Library). I'm not sure if <conio> is included since it is DOS specific I believe. Use <conio.h> just in case.


    using namespace std;

    is the same as ...

    std::cout >> something here;

    USING the namespace eliminates the need to write the prefix std::

    you could use the functions in the C++ headers without defining a namespace but you would have to put in that prefix for each std function, stream, what have you.
    My Avatar says: "Stay in School"

    Rocco is the Boy!
    "SHUT YOUR LIPS..."

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. #using namespace std;
    By mrafcho001 in forum C++ Programming
    Replies: 2
    Last Post: 11-10-2005, 04:47 PM
  2. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  3. *sigh* Using Namespace Std; Woes
    By KneeLess in forum C++ Programming
    Replies: 4
    Last Post: 10-06-2003, 04:41 PM
  4. using namespace std, What does it do?
    By Ben K. in forum C++ Programming
    Replies: 1
    Last Post: 10-14-2001, 10:42 PM
  5. What is "using namespace std; "
    By Engel32 in forum C++ Programming
    Replies: 3
    Last Post: 09-28-2001, 07:23 AM

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