<iostream.h> vs using std:://......

This is a discussion on <iostream.h> vs using std:://...... within the C++ Programming forums, part of the General Programming Boards category; i just got a new how to book and they use <iostream> and then Code: using std:://.... now this is ...

  1. #1
    Registered User blight2c's Avatar
    Join Date
    Mar 2002
    Posts
    266

    <iostream.h> vs using std:://......

    i just got a new how to book and they use <iostream> and then
    Code:
    using std:://....
    now this is called namespaces right? how's it better/worse than iostream.h and so on. thanks

  2. #2
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    The official way of doing things is not to include a .h at the end of any standard headers.
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

  3. #3
    Something Clever ginoitalo's Avatar
    Join Date
    Dec 2001
    Posts
    187
    Like SilentStrike said,

    using namespace std;
    is coded as the default namespace

    so you don't need to code stuff like std::cout
    everytime you need the std namespace.

  4. #4
    Registered User blight2c's Avatar
    Join Date
    Mar 2002
    Posts
    266
    ok. . . so what's the correct way to fix this

    Code:
    #include <iostream>
    #include namespace
    main()
    {
    	cout<<"hello";//notes
    	return(0);
    }

  5. #5
    Registered User
    Join Date
    Jan 2002
    Posts
    11
    #include <iostream>
    using namespace std;

    int main()
    {
    cout << "hello";
    return 0;
    }

  6. #6
    Registered User xds4lx's Avatar
    Join Date
    Nov 2001
    Posts
    630
    There isnt just one correct way. You can use the using directive to include all information from the header into the namespace (this is called global napespace pollution which is what happens when you include iostream.h) or you can just use the scope qualifier ( :: ) and qualifiy each function, class, or so on that you need like:
    Code:
    #include<iostream>
    using std::cout;
    using std::endl;
    
    int main()
    {   cout << "Hello" << endl;
        return(0);
    }
    "only two things are infinite, the universe and human stupidity, and im not sure about the former." - albert einstein

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. <iostream.h> or <iostream>?
    By {MaX} in forum C++ Programming
    Replies: 18
    Last Post: 06-05-2006, 12:52 AM
  2. <iostream.h> or <iostream>?
    By Yumin in forum C++ Programming
    Replies: 30
    Last Post: 01-31-2006, 01:00 AM
  3. <iostream.h> or <iostream> ??
    By Lazy Student in forum C++ Programming
    Replies: 8
    Last Post: 11-18-2002, 07:58 PM
  4. <stdio.h> and <iostream.h>
    By Jaguar in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 07-22-2002, 08:31 PM
  5. #include <iostream.h>
    By helbovine in forum C++ Programming
    Replies: 8
    Last Post: 02-09-2002, 06:10 PM

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