Difference between 'using' and 'using namespace'

using namespace makes visible all the names of the namespace, instead stating using on a specific object of the namespace makes only that object visible.


#include <iostream>

void print(){
using std::cout; 
using std::endl;
cout<<"test1"<<endl;
}
int main(){
 using namespace std;
cout<<"hello"<<endl;
print();
return 0;
}
  • while using "using namespace std" all the elements under the scope of std are made available under scope of the function.
  • while using "using std::cout" we explicitly mention what element under the std is required for the function ,without importing all the elements under std.

this is my first answer in stack overflow please correct me if iam wrong!!

Tags:

C++

Namespaces