#include#include using namespace std; int main() { vector v={1,2,3,4,5}; int n = 10; v.resize(n); cout<<"New size of the vector is "<
In the above example, we have defined a vector of integers ‘v’ of size 5. We have used the resize() function to resize the vector to 10. After resizing the vector, the current size of the vector is printed.
Example2:#include#include using namespace std; int main() { vector v={1,2,3,4,5}; cout<<"Vector before resize:"< In the above example, we have defined a vector of integers ‘v’ of size 5. First, we have printed the vector before resizing. After that, we have used the resize() function to resize the vector to 8. Then, we have printed the vector after resizing. Package Library: The vector class is a part of the C++ STL (Standard Template Library). Hence, the #include header file is required to use the vector class.