using namespace std
will import all of the symbols from std
into the enclosing namespace.
This can easily lead to name collisions, as the standard library is filled with common names:
get
, count
, map
, array
, etc.
A key concern with
using namespace std;
is not what is imported now but rather what may suddenly be imported in the
future.
While using namespace std;
is alright for tiny projects, it is important to move away from it as
soon as possible. Consider less intrusive options, if you insist on not using scope resolution:
// OK: *only* import std::vector
using std::vector;
// OK: namespace alias
namespace chr = std::chrono;
chr::duration x;
<:tccpp:865354975629279232>
Why is "using namespace std;" considered bad practice?
<:stackoverflow:874353689031233606>
Example of error caused by "using namespace std"
<:stackoverflow:874353689031233606>
Yet another example of an error