what is namespace std used in programs?? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

what is namespace std used in programs??

16th Jul 2016, 5:03 PM
MANJULA L
MANJULA L - avatar
3 Answers
+ 1
An answer of mine on a very similar question: The iostream header puts the classes and other elements in a namespace called "std" which also includes all other classes, functions etc. from the standard library (but those are put in separate headers). Namespaces are a way of preventing so called "name collision", i.e. multiple *definition* (not necessarily declaration) of the same symbol. This can occur in projects that are bigger than these presented here at SoloLearn C++ as homonyms become more likely to occur. A term is a homonym if this term is used in different meanings. It's the opposite of synonyms which denote different words for the same meaning. An example: the word "bow" is a homonym as it can mean the thing you use to play a violin or a (medieval) weapon. You could want to write a, let's say, role-playing game set in the middle ages. Then you might want to model in your code the weapon *and* the music utility. In order to distinguish between the weapon and the music utility without changing the name of the classes, you put one bow class in the namespace music and the other in the namespace weapon.
16th Jul 2016, 6:55 PM
Stefan
Stefan - avatar
0
prevent name collision when your using many libraries
16th Jul 2016, 6:00 PM
preethika
0
name collision ?? can u elaborate it plzz
16th Jul 2016, 6:03 PM
MANJULA L
MANJULA L - avatar