I am trying to understand vectors and assign(). I am following syntax of vectorname.assign(int Num, int value)
Below is the sample code. To my understanding 'value' will be assigned to 'Num' of elements in a vector. My query is why after assign() even the size() of container is getting changed. This should occur only when my container is small and the 'Num' is greater. Please correct me if I am wrong in my understanding.
int main()
{
cout << endl << "---- assign() on already ----" << endl;
// Assign vector
vector<int> v = {1, 2, 3, 4, 5, 6, 7, 8, 9};
cout << "Size : " << v.size() << endl;
cout << "Capacity : " << v.capacity() << endl;
cout << "The vector elements are: ";
for (int i = 0; i < v.size(); i++)
cout << v[i] << " ";
cout << endl;
// fill the array with 10 five times
v.assign(5, 10);
cout << "Size : " << v.size() << endl;
cout << "Capacity : " << v.capacity() << endl;
cout << "The vector elements after assign() using size() are: ";
for (int i = 0; i < v.size(); i++)
cout << v[i] << " ";
cout << endl;
return 0;
}