JonnyG
- 233
- 45
Let's take the count function for example. That's included in the iostream library (is library the correct word here?) which is why I type #include <iostream> at the beginning of my program. Now when I want to use the count function, I either have to type std::count or I can just type count but have to write using namespace std or using std::count before my main() function.
I was told that the reason why we have namespaces is because what if we use another library that also has a count function for example? The compiler won't know which count function to use. But why do we associate count with std? Isn't count a function in the iostream library? So wouldn't it make more sense to type iostream.count or iostream::count when we want to use the count function that specifically belongs to the iostream library?
What is the purpose of the namespace in this sense and what is the relationship between the namespace std and the library iostream?
I was told that the reason why we have namespaces is because what if we use another library that also has a count function for example? The compiler won't know which count function to use. But why do we associate count with std? Isn't count a function in the iostream library? So wouldn't it make more sense to type iostream.count or iostream::count when we want to use the count function that specifically belongs to the iostream library?
What is the purpose of the namespace in this sense and what is the relationship between the namespace std and the library iostream?