Initialise an STL vector from an array

by ixmx


#include <algorithm>
#include <vector>
using namespace std;
 
int my_array[]={1,2,45,6,67,8,99,05,33,2};
vector<int> my_vector;
 
int ARRAY_LENGTH = sizeof(my_array) / sizeof(my_array[0]) ;
 
my_vector.resize(ARRAY_LENGTH);
 
int * begin = my_array;
int * end = my_array + ARRAY_SIZE;
 
copy ( begin, end, my_vector.begin() );
 
 
 
Advertisements