Every #include
directive including something from the C++ standard library “loads” the entities into the std
namespace (or some other namespace like this).
The namespace helps preventing global namespace pollution – by keeping everything in a seperate namespace, identifier collisions are rendered impossible.
In the <vector>
file, then there is something like
namespace std {
template<typename T> class vector {
...
};
}
As you see, the vector
template is still in the std
namespace.
In summary, you use an #include
preprocessor directive to use some facility provided in a header file. The file’s contents textually replace the #include
directive.
Still, these facilities are in a different namespace to prevent name clashing.
solved c++ using stl vector [closed]