Demonstrating the STL vector front and erase operations. : vector front « Vector « C++






Demonstrating the STL vector front and erase operations.

 
 

#include <iostream>
#include <vector>
#include <string>
using namespace std;


int main()
{
  string s("abcdefghij");

  vector<char> vector1(s.begin(), s.end());

  cout << "Popping characters off the front produces: ";

  while (vector1.size() > 0) {
    cout << vector1.front();
    vector1.erase(vector1.begin());
  }
  cout << endl;
  return 0;
}

/* 
Popping characters off the front produces: abcdefghij

 */        
  








Related examples in the same category

1.Get the first element in a vector