C++ standard vector resize() function
问题 resize() adds/removes elements based on the size given to it. reserve() reserves memory space and it will not reallocate memory. The question I have is whether resize also works the same as in the capacity of the vector will only not increase? To add, would a combination of: std::vector<X> vector; vector.reserve(5); vector.resize(5); make any sense? Is it redundant? The goal here is to be able to overwrite values in the vector without having the vector allocate any extra space. 回答1: From this