Hi there,
There is a difference between a library and a namespace.
When you include the iostream header file, you make sure that the compiler knows about all the classes and functions you could be using in your program, such as std::cout and std::cin.
Namespaces are used to keep all the names of classes, functions and variables separate, which allows you to organize your code in a tidy way. For instance:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
namespace ascii_string {
void replace();
void substring();
}
namespace utf8_string {
void replace();
void substring();
}
//We now have 2x replace and 2x substring, but we can keep them apart as such:
ascii_string::replace();
ascii_string::substring();
utf8_string::replace();
utf8_string::substring();
| |
So the namespace "std" is a namespace for everything in the standard library. This makes sure that if, for example, you define your own function and you would call it, for instance "cout", the compiler still knows which "cout" to use. Note that for this purpose, it is generally recommended not to do
using namespace std;
for an entire program, only at a local function scope and only if you really need to.
So, if you don't do
using namespace std;
, you need to type
std::cout
to let the compiler know that it can find the name "cout" in the "std" namespace.
Hope that makes sense, more info on namespaces is available here: http://www.cplusplus.com/doc/tutorial/namespaces/
All the best,
NwN