Move position pointer and insert again : list insert « List « C++






Move position pointer and insert again

  
#include <string>
#include <list>
#include <iostream>

using namespace std;

int main()
{  
   list<string> staff;

   staff.push_back("A");
   staff.push_back("B");
   staff.push_back("C");
   staff.push_back("D");

   list<string>::iterator pos;
   pos = staff.begin();
   pos++;
   pos++;
   pos++;

   staff.insert(pos, "E");

   pos = staff.begin();
   pos++;

   staff.erase(pos);

   for (pos = staff.begin(); pos != staff.end(); pos++)
      cout << *pos << "\n";

   return 0;
}
  
    
  








Related examples in the same category

1.Insert elements of array into a list
2.Combine insert and begin to add element to the start of a list
3.Combine insert and end to add elements to the end of a list
4.Fill list with random numbers with generate function
5.Initialize a list with values in a vector