using namespace std; vs std::

Throughout my time looking through questions on this forum I have noticed that a lot of people do not use the namespace std. I want to know why as it seems tedious to write std:: along a large code. Isn't it simpler to just include 'using namespace std?'

from my modest experience in this language:

the std namespace is really large and contains so many identifiers.
for use in small projects, it's not really that bad, but when you work on a large project, and include a punch of standard headers, include some STL headers.
you would probably want to declare variables and functions with the same name of some standard identifiers, this will cause a problem to you, and will -even if compiled correctly- at least cost readability.

maybe there's another reason, but this is the one in my mind.
If it's too much for you to type, if you have a block of code where you know you'll be using lots of std:: stuff, then just stick using std::x; at the beginning of that block.
It follows the same scoping rules as everything else.
Doing using namespace std; takes the entire std namespace and dumps it into the global namespace... effectively defeating the entire point of having it in a separate namespace to begin with.

Remember that when you do using namespace std you are getting EVERYTHING in the namespace, not just the stuff you use. So other common names (like "count", for example) get dumped in, too... and increase the risk of a name conflict.
"std::" is fun to type :)
Topic archived. No new replies allowed.