resize(): It resizes the vector to the specified number of elements. This function will resize the vector
to the specified number of elements.
If the number is smaller than the vector's current size then the vector is truncated, otherwise
default constructed elements are appended.
Parameters:
new_size:- Number of elements the vector should contain.
Syntax:
vecName.resize(new_size)
For Example:
vec ={1,2,3,4}
vec.resize(10) => It resizes the vector of 10 length.
Approach
C++
#include <bits/stdc++.h>using namespace std;int main(){vector<int> vec = {1, 2, 3, 4};vec.resize(10);cout << vec.size() << "\n";return 0;}
No comments:
Post a Comment