size vs capacity of a vector?

后端 未结 6 1649
刺人心
刺人心 2020-11-27 03:10

I am a bit confused about this both of these look same to me. Although it may happen that capacity and size may differ on different compilers. how it may differ. Its also sa

6条回答
  •  无人及你
    2020-11-27 03:56

    Size: the number of items currently in the vector

    Capacity: how many items can be fit in the vector before it is "full". Once full, adding new items will result in a new, larger block of memory being allocated and the existing items being copied to it

提交回复
热议问题