cpp library

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!

closed account (Dy7SLyTq)
because the std namespace is spread across the whole stl
actually i am beginner would you mind to please explain it in detail i didn't get your last reply!
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.
got it! thank you very much!
one more thing i wanna ask that is iostream is a subset of using namespace std?
closed account (Dy7SLyTq)
no its a header that has all of its code contained in std
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.
ohh..thats the thing! thank you very much disch!..:) keep it up! carry on helping beginners like me!
Topic archived. No new replies allowed.