Another way to change the data in a vector is with the .pop_back() method, which removes the last element from a vector:
vector<int> threeArr = {1, 4, 6};
// Remove last element:
threeArr.pop_back();
// threeArr is now {1, 4}
// Remove last element again:
threeArr.pop_back();
// threeArr is now {1}
Assignment
Follow the Coding Tutorial and let's play with some arrays.
Hint
Look at the examples above if you get stuck.
Free plan: 30 tutor messages. PRO is unlimited.
Saved
Ctrl + Enter to check
