populate a new list with the elements of list2 : list assign « list « C++ Tutorial






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

using namespace std;

int main() 
{ 
  list<int> list1;

  size_t n = 10; 
  double val = 3.14; 
  list<double> list2(n, val);   

  list<double> list3(list2);    

  cout << "Size of list1 " << list1.size() << endl; 
  cout << "Size of list2 " << list2.size() << endl; 
  cout << "Size of list3 " << list3.size() << endl; 

  // populate a new list with the elements of list2 
  list<double> list4; 
  list<double>::const_iterator i; 
  for (i = list2.begin(); i != list2.end(); ++i) 
  { 
    list4.push_back(*i); 
  } 
  // Print every character in the list 
  for (i = list4.begin(); i != list4.end(); ++i) 
  { 
    cout << *i << ","; 
  } 
  cout << endl; 
  return 0; 
}








17.3.list assign
17.3.1.make a list from a list with list_copy()
17.3.2.populate a new list with the elements of list2
17.3.3.make a list of floats from a list of ints
17.3.4.Use list.assign to replace contents of a list with elements of another list