Why do we use using namespace std

why we are using using namespace std
it’s a header file or something else ?

Hi @thekaif7
A namespace is designed to differentiate similar functions , variables etc. with the same name available in different libraries. Using namespace, you can define the context in which names are defined.

Now let’s see what namespace std is :

std is an abbreviation of standard. std is the standard namespace. cout, cin and a lot of other things are defined in it. you can also call these functions using std::cout , std::cin etc.

What using does :

The keyword using technically means, use this whenever you can. This refers, in this case, to the std namespace. So whenever the computer comes across cout, cin, endl or anything of that matter, it will read it as std::cout, std::cin or std::endl.

When you don’t use the std namespace, the computer will try to call cout or cin as if it weren’t defined in a namespace (as most functions in your codes). Since it doesn’t exist there, the computer tries to call something that doesn’t exist! Hence, an error occurs. so essentially , without using namespace std; when you write for example cout << value; you’d have to put std::cout << value;

Note : namespaces are only available in C++.

Hope it helps
Mark resolved if satisfied :slight_smile:

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.