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

Refresh

5 days ago

Views

19 time

-2

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 */
 //.....

 srand(time(nullptr));

list<int> listA; 

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

vector<int> vectorA;
vectorA.reserve(10);
    //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