When you have "using namespace std" in a source file, you are telling the
compiler to declare everything that exists in the namespace std in your
current scope. If you then try to use a class or function from some other
source in you current scope that has the same name as one in namespace std,
you will get an error. This sort of defeats the purpose of namespaces.
By using "using std::", you are telling the compiler to only declare that
specific object, and will only get an error if you use another object with
that name. This allows you a bit more leeway when naming classes and
Now you will only get an error if you use another object named cin or cout,
you can use endl, vector, min(), max(), etc. without an error.
In circumstances where you have to use two or more objects with the same
name in you current scope, then you can prepend "std::" where it is used to
tell the compiler the difference. Example:
int a = 1;
int b = 2;
int c = std::max(a, b);
int d = 3;
int e = 4;
int f = foo::max(d, e);
This will tell the compiler to use the max function from the namspace std
for the one call, and to use the max function from the namespace foo for
My advice would be the following:
1) Don't use "using namespace std" since this clutters the namespace for
you current scope, and increases the likelihood that you will need to
specify a namespace for each conflicting function call and use of a class.
This gets to be error-prone and aggravating.
2) Do use "using std::<name>", most of the time this will be sufficient.
Doing this also lets other people working with your code know which
namespace a given class comes from, which can let them know what interface
and behavior to expect.
[ See http://www.yqcomputer.com/
[ comp.lang.c++.moderated. First time posters: Do this! ]