Some lists do not have a fixed length. A delivery can add another stock count after the list is created. std::vector is a collection whose size can change while the program runs.
Include <vector>, then write the element type inside angle brackets. std::vector<int> holds integers. Unlike std::array<int, 3>, the vector type does not include a fixed count. Braces provide its initial elements; empty braces create an empty vector.
#include <vector>
#include <iostream>
int main() {
std::vector<int> deliveries{4, 7};
deliveries.push_back(2);
std::cout << deliveries.size() << '\n';
std::cout << deliveries[2] << '\n';
}
push_back(2) adds one element at the end. The previous elements keep their order, and the size changes from two to three. The new last element has index two. This example prints 3 and 2.
Use size() to ask how many elements exist now, rather than remembering the starting length. The result is an unsigned size type suitable for counts, as with std::array. A vector can be indexed with square brackets, but it has the same boundary rule: the index must be smaller than the current size. An empty vector has no valid index at all.
Growing a vector does not require you to manage its storage yourself. You work with values and operations; the collection manages its storage. Later lessons explain why keeping a pointer to an element across growth requires care. For now, access elements directly through the vector.
Add the new values at the TODO comments, after each vector is created and before its output. The supplied checks wait until the new positions exist before reading them. You do not need to change those checks or enlarge a declared array bound: push_back creates the new element and updates the vector's size.
morning.push_back(9) at Task 1 to add the new delivery. Expect Morning count: 3 and Morning added: 9. The supplied guard checks the new element only after it exists.4 to afternoon with push_back. The guarded probe will print Afternoon total: 8 + 4.Edit main.cpp, then select Run to inspect the Console. Select Submit to check your completed tasks.