The size and capacity of vector in C++, the understanding of empty and non-empty

C++First P340

When a vector object is an empty container, it cannot be copied, assigned, accessed and some related write operations (such as fill_n, copy and other functions). The so-called empty container has nothing to do with its capacity (that is, memory space capacity, the maximum number of elements that can be stored), but only with its size (size, the number of elements that have been stored).

When the resize() operation is performed on an empty container, its size becomes the specified value, and the capacity also becomes that value, and the container is not empty; and if the reverse() operation is performed on an empty container, the size is still 0, and the capacity becomes the specified value. value, the container is empty.


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325867245&siteId=291194637