Dislike using namespace std?

It seems as though more experienced programmers tend to write code with std::cout, std::string, etc., whereas less experienced programmers always write using namespace std;. They also tend to assume that, in code snips, it is already included.

Why is this? If it's a dislike, what's the problem with it? As stated in the namespaces tutorial on this site, a namespace can be overridden if need be. Is it the case that you have written your own namespaces? Or that you so seldom use things like the STL and stdin/out that it just isn't necessary?
When I see cout in someone's program, how do I know if it's std::cout or some other user-defined variable called cout? I have to read the whole thing.

While that is a word that's unlikely to be used as a variable, how about count, begin, swap, copy, remove, array, max, or ignore? (all those names exist in namespace std, in different headers, but standard headers may include other standard headers, so I can't just look at the list of #includes)

Is it the case that you have written your own namespaces?

For a one-off forum post, no (and using namespace std; is just fine in a small .cpp file), but at work, there are hundreds of namespaces, some three or four levels nested. Any using declaration would make things far too confusing.
Last edited on
Well... this is pretty much what Cubbi already said, but by someone else.
So, instead of
using namespace std;
cout << "Foo" << endl;
using myOtherNamespace::cout;
using myThirdNamespace::endl;

You'd rather see
std::cout << "Bar" << std::endl;
myOtherNamespace::cout // plus whatever it does
myThirdNamespace::endl // plus whatever it does 

Now that I've typed it out, I realize how much more typing it is. Aside from being less than clear which namespace you're using. Thanks for helping me realize that.

But now I have a question. For nested namespaces, how do you specify which level you want?
// Like this?
Last edited on
Someone on here a long time ago suggested I use std:: and since I have been in the habit of doing so. Now I do not like cout cin etc... without the preceding std::
Perfect example of why this is a thing:

Topic archived. No new replies allowed.