what is tha work of using name space? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

what is tha work of using name space?

why do we use it? can't we make a program without it?

11th Jun 2016, 4:04 AM
Sabyasachi Panda
Sabyasachi Panda - avatar
4 Answers
+ 1
It's a solution to eliminate name conflict
11th Jun 2016, 8:11 AM
Shaowei Zhang
Shaowei Zhang - avatar
+ 1
You can program without ever using a namespace globally! Many programmers think this is best practice too. Because if didn't write `using namespace std;`, we would have to write `std::cout`, `std::cin`, etc. for all the standard library functions. While this saves a lot of effort, imagine you started using a global namespace for this one library that had a `vector` function. Then one day you load up another global namespace for another library that also has a `vector` function in it. You now have two `vector` functions, how do you differentiate them? If you remove your namespace for each, you'll be calling them more like this: `math::vector`, and this: `newLibrary::vector`. This is why programmers consider using namespaces a bad thing. As a beginner, this is alright though, just be careful in the future. ;)
11th Jun 2016, 11:22 AM
Lucius Latham
Lucius Latham - avatar
0
pta nhi
11th Jun 2016, 4:27 AM
Amitoj Wadhera
Amitoj Wadhera - avatar
0
u can make a program without using namespace std; ,for u to code without using namespace u have to put"::std before and after ur cout statement
11th Jun 2016, 5:40 AM
ANAGA IFEANYI EMMANUEL
ANAGA IFEANYI EMMANUEL - avatar