# Appending a vector to another vector

This topic is 4653 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

If I have two std::vector<int>, a and b, is there a good way to copy the elements of b into a, so that a would contain elements of a + elements of b? Another way than just looping through b, and push_back elements to a?

##### Share on other sites
copy(b.begin(), b.end(), back_inserter(a));

##### Share on other sites
Ah... nice... I knew there had to be some nice way of doing it..

##### Share on other sites
There's also insert, although I suppose that's a little less general than jdhardy's approach.
vector<int> a;vector<int> b;a.insert(a.end(), b.begin(), b.end());