Hi, I have gone thru a tutorial about vectors in cppreference.co m and it says that the reserve() function in vector allocates space for vector. But if I allocate some space for vector and try to give some value using the [] operator, it crashes.
What is the use of vector function() reserve?
Code:
vector<int> vect; vect.reserve(5); cout << "Capacity - " << vect.capacity() << endl; //it gives 5 vect[0] = 10; //it crashes, saying out of range value given
Comment