The problem with
using namespace std;
is that it can cause naming conflicts (it brings into the global namespace all of std that is in whatever header files one has included), and undermines the whole purpose of having namespaces - which is to help prevent naming conflicts. There are lots of ordinary English words that exist in std, such as left, right which are both defined in iostream. So if one had a variable or function named
left
, there is a conflict with
std::left
. It's worse the more includes one has - especially with the algorithm header file.
It might seem easy to have
using namespace std;
now,
but it will bite you one day.
It is possible to do this:
1 2 3
|
using std::cout;
using std::cin;
using std::endl;
|
but that gets tiresome as well, it's easy to accumulate lots of them. The easiest thing to do in the end is to get put
std::
before every std thing. That is what all the experienced coders do, so one might as well get ahead of the game now :+)
Also, using
std::
is explicit -
std::copy
means just that, not
boost::copy
or some other
copy
from a different library.
Ideally one should put their own code into it's own namespaces.