Libraries and Namespaces

C++ comes with a number of standard libraries.Some libraries are commercial & limited to perticular compiler while some are included in every compiler.These libraries place their definitions inside namespace.So we’ll discuss what namespace is,but before moving onto namespace let’s clear few things about libraries. 
Libraries
In C++,you came across so many built-in libraries.You can use these libraries in your program with the help of include directive.An include directive for a standard library has the form:

#include<iostream>

You’ve already used the iostream  library in your program.Include directive is preprocessor directive that add the information from library file.Here,library name is the name of header file that includes all the definition of items in the library.

Note: Most older compilers like Turbo C++ 3.0 do not confirm to the current namespace standard.So your usage of the standard library is restricted with these old compilers.With these compilers you’ve to write the library filename extention as .h,and you do not need the using directive.

Namespace
Namespace is simply a collection of name definitions,like class and variable declarations.With namespace you can reuse the names of classes,functions, and other items by qualifying the names to indicate different uses.This allows your code to be modular & reusable.You can have more than one namespace in your program.But it is manadatory to write using directive,if you’ve used any namespace in program.For example,if you’re writing standard I/O program then you must include these lines in your program.

#include <iostream>

using namespace std;If you want to make specific part of namespace available to your program like std::cin or std::cout then you can modify the using directives as shown below.
using std::cin;
using std::cout;
using std::endl;
This can be helpful if you’re using multiple namespace.

Creating Namespace
You place a name definition in a namespace by placing it in a namespace grouping.You just have to palce your code inside the namespace which in turn will be available as part of the namespace throughout the program.This way namespace can be helpfull in larger programs.

namespace Name_Space_Name
{//functions etc Or any other code goes here.}

You can even nest your namespace or can have two different namespace in your program.As well as you can have unnamed namespace which makes name definition local to a compilation
unit.

There are three ways you can use the namespace in your program:
1. by making all the names in the namespace available with a using directive.
2. by making the single name available with a using declaration for the one name.
3. by qualifying the name with the name of the namespace and the scope resolution operator.

To use this namespace all you’ve to do is use the using directive.For example:
using namespace Name_Space_Name;

 You can easily test this if you use modern IDE’s like Dev-C++,Visual C++ express and Turbo explorer.Again if you’re using older compilers like TC3 & VS5.0 which do not supprort namespaces,above information doesn’t apply to them.

I hope the information helped.If you have any questions or comments, please don’t hesitate to post them here.Please note:I will not entertain source code & project requests.