CIS 250 - The vector class
Objectives
- demonstrate the use of the vector class
- demonstrate techniques with vectors
vector class
- vectors are like having a dynamic array that you can add and remove items from
- use: #include <vector>
- use: using std::vector;
- example using an imaginary Pet class:
- declare a vector to hold Pet objects: vector<Pet> pets;
- create a Pet object: Pet pet(param1, param2, ...);
- add the Pet object to the vector: pets.push_back(pet);
- accessing the first Pet object in the vector: pets[0]
- getting the size/length of the vector: pets.size()
- accessing the last Pet object in the vector: pets[pets.size()-1]