Using the STL with the new namespace Feature of the C++ Standard

include

To use an stl vector, for example you want to use the following form of include:

#include <vector>

Note that it does not say <vector.h>, just <vector>. This is the new recommended C++ include style.

Namespaces

Namespaces define scopes, so there is a scope called std with all of the STL features. Once you have done the appropriate include, as above, you can create a vector with:

std::vector<int> my_storage;

Note the use of the scope resolution operator:: to get access to the scope defined by namespace std.

If you are going to make use of a lot of the stl features, you might want to use a shorthand: the using statement.

int main()
{
using namespace std; // opens the namespace scope
vector<int> my_storage; // don't need the scope resolution operator here.
my_storage.push_back(123);
...
}

After a using statement you don't need to use the scope resolution operator to get access to the features defined within the namespace. On the other hand, things defined in the local scope may conflict with things defined in the namespace. Local names will take precidence over the names from the namespace.