using namespace [namespace]
Allows you to omit the [namespace] from the fully qualified name.
For instance, if you'd want to print something to the screen, you'd need something like the following code:
#include <iostream>
int main()
{
std::cout << "Hello" << std::endl;
return 0;
}
As you can see the output stream cout is referred to with its fully qualified name including the namespace std as well: std::cout.
If you are feeling lazy to type the namespace all the time you can use the using namespace std statement, which allows you to not to write only the output stream without the fully qualified name.
#include <iostream>
using namespace std;
int main()
{
cout << "Hello" << endl;
return 0;
}
Notes
- There could be naming clashes (that's why there are namespaces in the first place), so you may not always be able to use a namespace in your code.
- You must not use namespace pollution, that is, apply the using namespace instruction in header files as anyone who includes this file will have the same using applied, even though it may not be desired (see point 1 above).