Can someone explain what we get when declare:
using namespace std;
and
using std::cin;
What are the differences?
using namespace std;
imports every symbol in the std
namespace into the present namespace. It is a using-directive. From the c++ wiki page on namespaces:
using namespace ns_name;
From the point of view of unqualified name lookup of any name after a using-directive and until the end of the scope in which it appears, every name from namespace-name is visible as if it were declared in the nearest enclosing namespace which contains both the using-directive and namespace-name.
using std::cin;
imports only the std::cin
symbol into the present namespace. It is a using-declaration. From the same wiki page as above:
using ns_name::name;
makes the symbol name from the namespace ns_name accessible for unqualified lookup as if declared in the same class scope, block scope, or namespace as where this using-declaration appears.