make a vector from a list with vector_copy : list vector « 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 vector from a list
   vector<int> vector_copy( original.begin(), original.end() );

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








17.19.list vector
17.19.1.assign a list to a vector
17.19.2.create an empty vector of int's and assign a list of doubles to it
17.19.3.Vector of list of strings
17.19.4.make a vector from a list with vector_copy
17.19.5.Transfer vector to a list and remove all negative numbers with bind2nd and less