How is the pop_back() method used in vectors?

The pop_back() method of a vector is used to remove the last element of the vector. Here is how it is used:

vector<int> nums;
nums.push_back(1);
nums.push_back(2);
nums.push_back(3);

nums.pop_back(); // 删除最后一个元素,此时nums中仅剩下1和2

for(int num : nums){
    cout << num << " ";
}

The output is:

1 2

Please note that the pop_back() method does not return any value, it is only used to delete the last element.

bannerAds