using namespace std; vs. std::

I noticed that there are many codes that contain std::, so why not use using namespace std;?I think its easier to use than to repeat std:: through the entire code.
Thanks.
This question has been asked many times in these forums. Perhaps you could use the site's search feature to find a
satisfactory answer.
Here's a reply I made several months ago to this same question:

jsmith wrote:

You should also understand why namespaces were added to the language in the first place,
because a "using namespace std;" in a .cpp file defeats the purpose of namespaces in that
.cpp file.

Namespaces were added to avoid global name conflicts. For example, you might be using
two libraries, both of which define a class called "List". If those declarations are not in
a namespace, then you end up with ODR (one definition rule) violations that lead ultimately
either to compile errors or unexpected runtime behavior. By putting the declarations in
separate namespaces and referring to them with their fully qualified name, there is no
ambiguity as to which one you mean.

When you use blanket "using namespace" clauses, you potentially reintroduce those
ambiguities.

Having said all this, unless you are compiling against multiple external libraries or are working
on an extremely large project, you _probably_ won't have any troubles by just writing
"using namespace std;" in your .cpp files.


http://www.cplusplus.com/forum/beginner/19931/
Sorry I forgot to use search. Thanks jsmith for the info.
Here is a thread that demonstrates how you can sometimes cause trouble with the using declaration.

http://www.codeguru.com/forum/showthread.php?t=498140
Topic archived. No new replies allowed.