cpp library

Aug 1, 2013 at 5:48pm
i want to know that #include <iostream> it included std. input output library and
using namespace std also included standard lib. then why we have to write both things? please explain it in detail!

Aug 1, 2013 at 5:55pm
closed account (Dy7SLyTq)
because the std namespace is spread across the whole stl
Aug 1, 2013 at 5:59pm
actually i am beginner would you mind to please explain it in detail i didn't get your last reply!
Aug 1, 2013 at 6:03pm
closed account (Dy7SLyTq)
iostream didnt include std. it gives the user the abiltity to bring anything contained in the std namespace (in that file at least) into scope with the command using.
Aug 1, 2013 at 6:17pm
got it! thank you very much!
Aug 1, 2013 at 6:23pm
one more thing i wanna ask that is iostream is a subset of using namespace std?
Aug 1, 2013 at 6:24pm
closed account (Dy7SLyTq)
no its a header that has all of its code contained in std
Aug 1, 2013 at 9:39pm
hellcoder:

You seem to be confusing headers and namespaces.

Including a header gains you access to any objects/functions/classes/etc that are defined in that header. For example, when you #include <iostream> , you gain access to std::cout, std::cin, std::ostream, etc, etc.


Notice how all of that has the 'std::' prefix. That is because it is all defined within the std namespace:

1
2
3
4
5
6
7
8
// a fully functional example program
#include <iostream> // for std::cout, std::endl

int main()
{
    std::cout << "hello world" << std::endl;
    return 0;
}



What using namespace std; does... is it takes everything in the std namespace and dumps it into the global namespace (effectively destroying the entire point of having a separate namespace).

This lets you access objects without the std:: prefix (ie.. you can just type cout instead of std::cout) but increases the likelihood of name conflicts in your program... since you might accidentally name a function/class the same thing as something already in the std namespace.
Aug 2, 2013 at 5:37pm
ohh..thats the thing! thank you very much disch!..:) keep it up! carry on helping beginners like me!
Topic archived. No new replies allowed.