Why do we need to add namespace tag | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why do we need to add namespace tag

12th Oct 2020, 4:34 AM
Bharadwaaja Kanakadandi
Bharadwaaja Kanakadandi - avatar
4 Answers
+ 5
In academic environments, it can frequently be the case where many are condemned for not using 'using namespace std'. Lecturers, especially those who lack experience in actual software development, want an easy job marking the papers. Were we taught about it's purpose and why 'using namespace std' is needed, or how it works? No. We weren't even taught what namespaces are. It is simply a bad practice to freely use something when you don't understand how it works. What I see essential is for namespaces to be taught to beginners with sufficient explanation, and not forced upon them. The recent disagreements I had with the system got me trying to not use it (which is a royal pain once you've stuck with it for some time, all the more reason to eliminate blind practice of 'using namespace std').
12th Oct 2020, 5:47 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 4
Because Namespaces allow us to group named entities that otherwise would haveglobal scope into narrower scopes, giving them namespace scope. This allows organizing the elements of programs into different logical scopes referred to by names. Namespace is a feature added in C++ and not present in C.
12th Oct 2020, 4:37 AM
🔰Saurabh🔰
🔰Saurabh🔰 - avatar
+ 2
Source of Mr. White's response: https://www.geeksforgeeks.org/namespace-in-c/
12th Oct 2020, 5:41 AM
Ipang
0
It is also good to know that namespaces will get you in trouble if the same function is in two code pacakges. That is why in larger projects, you normally don't use namespaces and instead call it directly std::cin.
13th Oct 2020, 11:10 PM
The Darkness
The Darkness - avatar