STL Convert Vector to list

Discussion in 'C++' started by Travis, Oct 25, 2007.

  1. Travis

    Travis 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.

    Thanks,
    Travis, Oct 25, 2007
    #1
    1. Advertising

  2. Travis

    Guest

    On Oct 25, 4:41 pm, Travis <> wrote:
    > 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.
    , Oct 25, 2007
    #2
    1. Advertising

  3. On 2007-10-25 22:41, Travis wrote:
    > 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());

    --
    Erik Wikström
    =?UTF-8?B?RXJpayBXaWtzdHLDtm0=?=, Oct 25, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dennis
    Replies:
    1
    Views:
    2,579
    Dennis
    Jun 7, 2004
  2. CD
    Replies:
    2
    Views:
    803
    Victor Bazarov
    Oct 5, 2004
  3. Replies:
    8
    Views:
    1,913
    Csaba
    Feb 18, 2006
  4. ehui928
    Replies:
    2
    Views:
    461
    ehui928
    May 29, 2006
  5. Luca Risolia

    STL map to STL vector

    Luca Risolia, Jan 13, 2014, in forum: C++
    Replies:
    32
    Views:
    360
    Seungbeom Kim
    Jan 18, 2014
Loading...

Share This Page