why do advance users use the namespace?

What I mean is why do they put the namespace in front of alot of the code they write e.g
 
std::cout << "Like this."<<endl;

sorry if this is a silly question im just curious
You mean...

std::cout << "Like this." << std::endl;

;-)

I don't think it's necessarily advanced users. I think readability is one reason. You're also not going to get any errors due to ambiguity in variable names.

They're my two reasons.

1
2
3
4
5
6
7
8
9
10
11
#include <iostream>

using namespace std;

int main(){
    std::cout << '[';
    cout << endl;
    int endl = 0;
    cout << endl << std::endl;
    std::cout << ']';
}


cout referes to std::cout. Before endl was declared as an int, it use to refer to std::endl, but after it now is an int.
Last edited on
That seems very situational for so many people(That ive seen) to use it
When you do using namespace std; you are taking everything in the std namespace (not just the stuff you wanted... but everything) and dumping it into the global namespace.

This defeats the entire purpose of having a namespace to begin with. The whole point is to keep things separate so that there is less confusion and less chance of a name conflict.
Topic archived. No new replies allowed.