using namespace std; vs using std::x

Hey, so I keep seeing people using the using namespace std; deal. I personally just do the using::std x structure. For example, I see programs started like:

#include <iostream>
using namespace std;

and my programs start like this:

#include <iostream>

using std::cout;
using std::cin;
etc....

Why is there a difference? I tried googling this already, I couldnt find much on it. Is one way better than the other? What exactly does using namespace std; do?

Thanks ahead of time! Look forward to some answers :D
when you use using namespace std its like opening the garage door to let everyone see all your crap. it allows everything under that namespace to be used. when you do it the other way like st::cout you only allow 1 piece of it.
Hmmm, im still a noob too, but i would think that NAMESPACE is a variable?
namespace is not a variable. It's a keyword.
http://cplusplus.com/doc/tutorial/namespaces/
Ok so unless you need to use everything in whatever library, use the std:: format? And does using namespace std; work for any library?
And does using namespace std; work for any library?

No. But,
All the files in the Standard C++ Library are included in namespace 'std'.

Unless you are creating a very BIG program AND you run out of names for your variables, func......., use the using directive, Otherwise you will simply be wasting your time typing extra stuff.
Last edited on
Unless you are creating a very BIG program AND you run out of names for your variables, func......., use the using directive, Otherwise you will simply be wasting your time typing extra stuff.


Ehhhh.

I can't say I agree.
Last edited on
Let's just say that among other things it's very handy to be able to just look at your code and instantly know which library what's in, just by the namespace:: prefixes. ;)

-Albatross
Sorry for not being active in here! I forgot to subscribe to this :/ So using the using directive or namespaces, which is better? Right now, I am still just working in console apps, hoping to start working on window apps soon.
Topic archived. No new replies allowed.