std::vectro - append other vector container?

Discussion in 'C++' started by Gernot Frisch, Jul 28, 2004.

  1. Hi,

    how can I append the contents of one vector to another?

    std::vector <int> a, b;

    a.push_back(3); a.push_back(4);
    b.push_back(5); b.push_back(7);

    a+=b;
    a.append(b);
    a.push_back(b);

    all doesn't work... Please help.
    -Gernot

    --
    -Gernot
    int main(int argc, char** argv) {printf
    ("%silto%c%cf%cgl%ssic%ccom%c", "ma", 58, 'g', 64, "ba", 46, 10);}

    ________________________________________
    Looking for a good game? Do it yourself!
    GLBasic - you can do
    www.GLBasic.com
     
    Gernot Frisch, Jul 28, 2004
    #1
    1. Advertising

  2. Gernot Frisch

    Sharad Kala Guest

    "Gernot Frisch" <> wrote in message
    news:...
    > Hi,
    >
    > how can I append the contents of one vector to another?
    >
    > std::vector <int> a, b;
    >
    > a.push_back(3); a.push_back(4);
    > b.push_back(5); b.push_back(7);
    >
    > a+=b;
    > a.append(b);
    > a.push_back(b);
    >
    > all doesn't work... Please help.
    >


    a.insert(a.end(), b.begin(), b.end());

    -Sharad
     
    Sharad Kala, Jul 28, 2004
    #2
    1. Advertising


  3. > a.insert(a.end(), b.begin(), b.end());
    >


    Ah... Thank you!
     
    Gernot Frisch, Jul 28, 2004
    #3
  4. "Gernot Frisch" <> wrote in message
    news:...
    > Hi,
    >
    > how can I append the contents of one vector to another?
    >
    > std::vector <int> a, b;
    >


    Try insert:
    a.insert( a.end(), b.begin(), b.end() );

    Hope it helps,
    Ruslan.
     
    Ruslan Abdikeev, Jul 28, 2004
    #4
    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. Vivi Orunitia
    Replies:
    11
    Views:
    4,542
    Martijn Lievaart
    Feb 4, 2004
  2. Steven T. Hatton
    Replies:
    4
    Views:
    3,984
    Rob Williscroft
    Dec 5, 2004
  3. Anonymous
    Replies:
    20
    Views:
    4,427
    Pete Becker
    Mar 30, 2005
  4. Jason Heyes
    Replies:
    8
    Views:
    767
    Andrew Koenig
    Jan 15, 2006
  5. Simon
    Replies:
    2
    Views:
    510
    Simon
    May 31, 2009
Loading...

Share This Page