Answers for "C++ Vector Operation Delete Elements"

C++
0

C++ Vector Operation Delete Elements

#include <iostream>
#include <vector>

using namespace std;

int main() {
  vector<int> num{1, 2, 3, 4, 5};
  
  // initial vector
  cout << "Initial Vector: ";
  for (int i : num) {
    cout << i << " ";
  }

  // remove the last element
  num.pop_back();

  // final vector
  cout << "\nUpdated Vector: ";
  for (int i : num) {
    cout << i << " ";
  }
  
  return 0;
}
Posted by: Guest on May-05-2022

Code answers related to "C++ Vector Operation Delete Elements"

Browse Popular Code Answers by Language