Start learning free

LESSON 109 OF 667 · ARRAYS I

Remove Last Item From Vector in C++

Lesson

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.


STEP 1 OF 2
    Ctrl + Enter to check