using namespace std

Hi everyone, I just noticed that (apparently) evrybody prefers to specify in the code the namespace of functions like `std::cout`. I'm wandering why. Is it any better than declare `using namespace std` before the main (or anywhere else)?
thanks in advance.

Good ref @JLBorges. You do keep them don't you? lol
Okay I got it. thanks guys.
> You do keep them don't you?

It was vaguely in my memory; I found it using a site specific google search site:www.cplusplus.com ...


> Why is “using namespace std;” considered bad practice?

It is not considered to be 'bad practice' universally; though it is 'bad practice' when used indiscriminately (as is a lot of other language features which can also be misused).

CoreGuidelines:
Use using namespace directives for transition, for foundation libraries (such as std), or within a local scope (only)

Reason using namespace can lead to name clashes, so it should be used sparingly. However, it is not always possible to qualify every name from a namespace in user code (e.g., during transition) and sometimes a namespace is so fundamental and prevalent in a code base, that consistent qualification would be verbose and distracting.
...
The use of using namespace std; leaves the programmer open to a name clash with a name from the standard library ... people who use using namespace std are supposed to know about std and about this risk.

https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rs-using

Also: Don’t write using namespace at global scope in a header file
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rs-using-directive
Older text from time when namespaces were a new thing: http://www.gotw.ca/gotw/053.htm
I avoid easily preventable problems by never having using directives and declarations, always fully qualifying namespace uses.

The Boost libraries make it difficult at times to maintain that stance, the multiple levels of namespaces can be a bit much.
Topic archived. No new replies allowed.