How does c++ std::vector work?

前端 未结 5 1134
北海茫月
北海茫月 2021-01-03 23:30

How does adding and removing elements \"rescale\" the data? How is the size of the vector calculated (I believe it is kept track of)? Any other additional resources to le

5条回答
  •  借酒劲吻你
    2021-01-03 23:40

    I wrote a vector in C++ a year or so ago. It is an array with a set size (ex. 16 chars) which is expanded by that amount when needed. That is to say, if the default size is 16 chars and you need to store Hi my name is Bobby, then it will double the size of the array to 32 chars then store the char array there.

提交回复
热议问题