#include#include using namespace std; int main() { vector v(3); // creates a vector with 3 elements v.resize(5); // increases the size of the vector to 5 for (int i = 0; i < v.size(); i++) { cout << v[i] << " "; // prints 0 0 0 0 0 (two new elements are added) } return 0; }
#includeIn both examples, `resize` function is used to change the size of the vector. The first example increases the size of the vector from 3 to 5, and the second example decreases the size of the vector from 5 to 3. The package library used is the C++ Standard Template Library (STL), which provides a set of container classes, algorithms, and iterators.#include using namespace std; int main() { vector v(5); // creates a vector with 5 elements v.resize(3); // decreases the size of the vector to 3 for (int i = 0; i < v.size(); i++) { cout << v[i] << " "; // prints first 3 elements, i.e. 0 0 0 } return 0; }