make a list from a list with list_copy() : list assign « list « C++ Tutorial






#include <iomanip>
#include <iostream>
#include <list>
#include <vector> 

using namespace std;

template <class T>
void print(T& c){
   for( typename T::iterator i = c.begin(); i != c.end(); i++ ){
      std::cout << *i << endl;
   }
}

int main( )
{
   const int data[] = { 1, 1, 2, 3, 5 };
   list<int> original( data,data + sizeof( data ) / sizeof( data[0] ) );

    // make a list from a list
   list<int> list_copy( original );

 
   // show results
   print( original);
   print( list_copy);
}








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