I know this is amateur but really want to know. Any help thanks
Asked
Active
Viewed 112 times
-7
-
7[Read up on namespaces](http://www.cplusplus.com/doc/tutorial/namespaces/). – Michael Jan 12 '15 at 16:01
-
8It is neither required [fact] nor recommended [opinion] – David Rodríguez - dribeas Jan 12 '15 at 16:04
-
related: [Why is “using namespace std;” considered bad practice?](http://stackoverflow.com/q/1452721/509868) – anatolyg Jan 12 '15 at 16:04
-
How is this "unclear what you're asking"? It's pretty clear... – Barry Jan 12 '15 at 16:13
-
There is an immense amount of tutorials saying to write "using namespace std;" without properly explaining its purpose beyond "so we can use iostream", so I think this is a reasonable self-learning beginner's question. – molbdnilo Jan 12 '15 at 16:25
-
@Barry I guess it's like when you ask a robot "Why does 2+2=5?", and then it says "I don't understand" and black smoke appears from its head... – anatolyg Jan 15 '15 at 17:11
1 Answers
4
It isn't required just to include <iostream>
, but using it makes the names in <iostream>
usable without the namespace name, so you can say cout
instead of std::cout
.
It's not the only way to use those names though, you can refer to it by explicitly qualifying it with the namespace i.e. std::cout
, or you can just re-declare that one name (and not everything else in namespace std
) with using std::cout;
C++ namespaces are used to arrange and group related code into a common namespace. The standard library defines everything in namespace std
so that the standard string
type does not interfere with other types called string
in other namespaces.

Jonathan Wakely
- 166,810
- 27
- 341
- 521