How do I copy elements which are stored in a int list to a int vector? [on hold]


February 2019


19 time


I have a task to copy a listx elements into vectory using STL algorithms. I have checked everywhere, seems there is no way. Does anyone know? Please help out.

I have created another vector with capacity to copy up to 10 elements. But my copy() function is not working.

/*Here is the chunk of a code */


list<int> listA; 

//Fill 10 numbers between 1-100
for (int i= 0; i< 10; ++i) {
    int rands= rand() % 100 + 1;

vector<int> vectorA;
    //Don't know how to copy?
    copy(listA.begin, listA.end(), back_inserter(vectorA));


Expected result is that, I successfully copy or put 10 elements from a list to an empty vector.

0 answers