Here is sample code to show the use namespace in C++.
output :
namespace ns1
namespace ns2
namespace ns2
Similarly, using namespace std is defined as :
#include<iostream>
namespace ns1
{
void print(){
std::cout<<"namespace ns1"<<std::endl;
}
}
namespace ns2
{
void print(){
std::cout<<"namespace ns2"<<std::endl;
}
}
int main(){
using namespace ns2;
ns1::print();
ns2::print();
print();
return 0;
}
output :
namespace ns1
namespace ns2
namespace ns2
Similarly, using namespace std is defined as :
// iostream header file
namespace std
{
ostream cout;
istream cin;
//
};