#includeusing namespace std; int main() { vector vec; vec.reserve(10); // allocates memory space for 10 elements return 0; }
#includeIn the above example, we have created an empty integer vector "vec" and resized it to allocate memory space for 5 integer elements using the resize() function. This function is also a member function of the vector class and can be used to allocate and initialize memory space for a specified number of elements. The vector allocation functionalities are part of the standard C++ library package.using namespace std; int main() { vector vec; vec.resize(5); // allocates memory space for 5 elements return 0; }