STL Convert Vector to list

T

Travis

I am using some client code that wants an STL list. I prefer the
vector for what I'm doing (so I can reference by index). Is there a
simple-ish way to convert a vector to a list.

Thanks,
 
A

AnonMail2005

I am using some client code that wants an STL list. I prefer the
vector for what I'm doing (so I can reference by index). Is there a
simple-ish way to convert a vector to a list.

Thanks,

You can do something simliar to this to make a copy:

std::copy (v.begin (), v.end (), std::back_inserter (l))

where l is your list and v is your vector.
 
G

Guest

I am using some client code that wants an STL list. I prefer the
vector for what I'm doing (so I can reference by index). Is there a
simple-ish way to convert a vector to a list.

std::vector<int> v;

// Fill vector

std::list<int> l(v.begin(), v.end());
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,681
Members
48,796
Latest member
Greg L.

Latest Threads

Top