mardi 5 mai 2020

Could not understand working of vector.resize() and vector.shrink_to_fit()

I came across 2 codes depicting the use of .resize() and .shrink_to_fit() and could not understand which one demolishes the elements of the vector.

Example 1

Example 2

In example-1 vector has all the elements even after .resize(5) is used while in example-2 .resize(4) eliminates the 5th element of the vector. Have a look and tell if I'm getting something wrong.

Aucun commentaire:

Enregistrer un commentaire