9/27/2017

Tip, Add 'Vector (b)' to end of 'Vector (a)'

If you have 2 Vector and you want to add Vector b to end of Vector a, refer to below code. (very simple!)

vector< int > a;
a.push_back(1);
a.push_back(2);
a.push_back(3);

vector< int > b;
b.push_back(4);
b.push_back(5);
b.push_back(6);

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

int count = 0;
for (auto it : a)
{
printf("a[%d] = %d \n", count++, it);
}



No comments:

Post a Comment