Coupon Accepted Successfully!


The Standard Namespace std

We frequently use the statement using namespace std. This statement inserts a complete library in the current program. This is similar to including a header file, and the contents of the header file are available in the current program. We can access all classes, functions, and templates declared inside this namespace.

using namespace std;

As studied earlier, the above method of specifying namespace is called a using directive. The above declaration makes it possible to access all members of the namespace directly. All header files also use the namespace feature. If we include header files and namespace together in the same program, the variable declared in the header file will be global. Instead of the above declaration, you should observe the following declaration in order to prevent serious bugs. Consider the following program:


21.21 Write a program to access members of namespace std applying using declaration method.


int main()


int age;

std::cout<<“\nEnter your age:”;


std::cout<<“\n Your age is:”<<age;




Enter your age : 24

Your age is : 24

Ansi and Turbo-C++ Keywords



Explanation: In the above program, the l member of namespace std cannot be accessed directly. Consider the following statement:

std::cout<<“\nEnter your age:”;

Here, the namespace name std is preceded by the object cout. In the same way, the cin object is accessed.

Guidelines for Defining Namespace

1.     The namespace is not terminated by semi-colon-like classes.

2.     Declarations done outside the namespace are considered members of the global namespace.

3.     Members of namespace are defined within the scope of namespace.

4.     The namespace cannot be defined inside any function; it should be global.

Test Your Skills Now!
Take a Quiz now
Reviewer Name