What are NameSpaces in C++ ? How do we use namespaces in C++ ?

 
 

The purpose of namespaces is to reduce the name clashes that occur with multiple independently developed libraries. It is used to package names, improve program readability and reduce the name clashes in the global namespace.
e.g. namespace mynamespace{    class Stack    {    }}The class Stack has to be referred as mynamespace::Stack.
In this way namespace facilitate building large systems by partitioning names into logical groups. Java has a similar concept called packages. One can access the names within the namespace in the following ways:      a. Use the scope resolution operator to prefix the object declared in the namespace with the name of the namespace.          e.g. mynamespace::Stack *s = new mynamespace::Stack ();      b. Using directive          E.g. using namespace Stack;          Stack *s = new Stack ();