One limitation of using arrays is that they can't expand dynamically if we want to add elements to them at run time. Vectors are special objects that don't suffer from this limitation. This video will show you how to create them.
Now that you can create and populate a vector, let's look at how to access the data that we've stored.
Review Questions
The following are examples of questions similar to what you can expect to see on the next exam.
- What is a vector? An object that contains an array, and keeps track of the capacity.
- Can vectors hold multiple data-types? No, like an array, you must define the type.
- How do you add an item to a vector? By calling push_back()
- How do you access an item in a vector? By using an iterator, or by the index Ex: person[4].