USING NAMESPACE

why do we use “using namespace std;” in every code of C++?

1 Like

If you are familiar with JAVA, think of std as the package where some standard functions and methods are defined. These standard functions are like the cin for taking user input and cout for printing.

Therefore, namespace std defines all of the standard functions like the cin and cout. So, if you plan to use them, you have to include or “use” the std namespace where these functions are defined.

On the other hand, if you don’t want to use the “using namespace std;”, you could still compile your c++ code. Only thing is you have to prefix std:: before any usage of std defined functions. Ex. std::cin, std::cout.

Interestingly, if you don’t use such functions, for example, say you use printf and scanf instead of cin and cout, then you don’t have to use “using namespace std;” at all.

3 Likes

google your queries before posting them here, there are many amazing answers on StackOverflow and Quora.Don’t increase traffic here.
Here is the link for your convenience.

https://www.quora.com/What-does-using-namespace-std-mean-in-C++

3 Likes