Using namespace

I couldn’t understand the use of “using namespace std;” What could happen if we exclude it?

Hey @himanshigupta579
When programs start to get really big, it gets difficult to keep track of all the functions and variables that you have already declared. This sometimes results in two different things being declared that have the same name. When this happens, the program will give you an error because the compiler can’t tell which is which anymore. This gets even worse when there are lots of different libraries involved in the program. A namespace is a more flexible way of adding prefixes. The std namespace is special; it is short for the word “standard.” The built in C++ library routines are kept in the standard namespace. That includes stuff like cout, cin, string, vector, map, etc. Because these tools are used so commonly, it’s popular to add “using namespace std” at the top of your source code so that you won’t have to type the std:: prefix constantly. And because these functions are kept in a namespace, if you really want to use “vector” as a variable name, you still can. Namespaces give you more freedom to use short, accurate names.
If you exclude writing this statement, normal cout , cin statements won’t work. You’ll have to put std:: prefix before them

1 Like

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.