Saturday, December 4, 2010


Say you want to insert from one vector v1 into another vector v2 starting at location offset 2 of v2. You could use the following function call:copy(v1.begin(), v1.end(), inserter(v2, v2.begin()+2);

You use inserter() because your input is vector and an iterator pointing where you want to insert() within that vector. If you want to insert at the end of vector v2, the third argument would be back_inserter(v2), which calls v2.push_back(). You can't use front_inserter(), because that calls v2.push_front(), which does not exist for vectors.

No comments:

Post a Comment