The best feature of a vector is its resizeability. A vector, once declared, can be resized from anywhere within the program. Suppose we have a situation where we input numbers from the user and store them in a vector till he inputs -1, and then display them. In such a case, we do not know the size of the vector beforehand. So we need wish add new values to the end of a vector as the user inputs them. We can use then vector function push_back for that purpose.
vector<int> numbers(5);
int size = 5;
for (int i = 0; i < size; i++) {
numbers[i] = i;
}
int end = 4;
for (int i = 0; i < size; i++) {
numbers[i] = numbers[end];
end--;
}
for (int i = 0; i < size; i++) {
cout << numbers[i] << " ";
}
cout << endl;