Combine insert and end to add elements to the end of a list : list insert « List « C++






Combine insert and end to add elements to the end of a list

  
 

#include <iostream>
#include <cassert>
#include <algorithm>
#include <string>
#include <list>
#include <iostream>
using namespace std;

void print_list(string s)
{
  cout << s << endl;
}

int main()
{
  list<string> dlist;

  dlist.insert(dlist.end(), "AAA");
  dlist.insert(dlist.end(), "BBBB");
  dlist.insert(dlist.end(), "CCCCC");

  
  for_each(dlist.begin(), dlist.end(), print_list);
  return 0;
}

/* 
AAA
BBBB
CCCCC

 */        
    
  








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.Fill list with random numbers with generate function
4.Initialize a list with values in a vector
5.Move position pointer and insert again