0

what exactly does v.assign ?

int main() { vector<int> v; v.assign(5,3); cout<<v.size()<<endl; }

8th May 2019, 1:13 PM
San Anemos
San Anemos - avatar
1 Answer
+ 1
its assign a value 3 in the first 5 elements. think the vector like an array. at declaration its still empty [] on .assign(5,3) it'll assign a new size, then it'll everything with 3 [3,3,3,3,3] more on that here https://en.cppreference.com/w/cpp/container/vector/assign
8th May 2019, 2:38 PM
Taste
Taste - avatar