C++ FAQ Celebrating Twenty-One Years of the C++ FAQ!!!
(Click here for a personal note from Marshall Cline.)
Section 27:
[27.5] Should I use using namespace std in my code?

Probably not.

People don't like typing std:: over and over, and they discover that using namespace std lets the compiler see any std name, even if unqualified. The fly in that ointment is that it lets the compiler see any std name, even the ones you didn't think about. In other words, it can create name conflicts and ambiguities.

For example, suppose your code is counting things and you happen to use a variable or function named count. But the std library also uses the name count (it's one of the std algorithms), which could cause ambiguities.

Look, the whole point of namespaces is to prevent namespace collisions between two independently developed piles of code. The using-directive (that's the technical name for using namespace XYZ) effectively dumps one namespace into another, which can subvert that goal. The using-directive exists for legacy C++ code and to ease the transition to namespaces, but you probably shouldn't use it on a regular basis, at least not in your new C++ code.

If you really want to avoid typing std::, then you can either use something else called a using-declaration, or get over it and just type std:: (the un-solution):

  • Use a using-declaration, which brings in specific, selected names. For example, to allow your code to use the name cout without a std:: qualifier, you could insert using std::cout into your code. This is unlikely to cause confusion or ambiguity because the names you bring in are explicit.
    #include <vector>
    #include <iostream>
    
    void f(const std::vector<double>& v)
    {
      using std::cout;  //  a using-declaration that lets you use cout without qualification
    
      cout << "Values:";
      for (std::vector<double>::const_iterator p = v.begin(); p != v.end(); ++p)
        cout << ' ' << *p;
      cout << '\n';
    }
    
  • Get over it and just type std:: (the un-solution):
    #include <vector>
    #include <iostream>
    
    void f(const std::vector<double>& v)
    {
      std::cout << "Values:";
      for (std::vector<double>::const_iterator p = v.begin(); p != v.end(); ++p)
        std::cout << ' ' << *p;
      std::cout << '\n';
    }
    

I personally find it's faster to type "std::" than to decide, for each distinct std name, whether or not to include a using-declaration and if so, to find the best scope and add it there. But either way is fine. Just remember that you are part of a team, so make sure you use an approach that is consistent with the rest of your organization.