-1

Can someone explain what we get when declare:

using namespace std;

and

using std::cin;

What are the differences?

cadaniluk
  • 15,027
  • 2
  • 39
  • 67
Inception
  • 177
  • 1
  • 2
  • 8

1 Answers1

1

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.

Community
  • 1
  • 1
jaggedSpire
  • 4,423
  • 2
  • 26
  • 52