Any clean way to get from one to the other? erase() has been pretty vexing for me.

Add the int to some known iterator?

#include <iostream>
using std::cout;
using std::endl;
#include <vector>
using std::vector;
#include <algorithm>
using std::copy;
#include <iterator>
using std::ostream_iterator;

int main()
{
   static const int init[] = {10,20,30,40,50,60,70,80,90,100};
   vector<int> v(init, init + sizeof init / sizeof *init);
   copy(v.begin(), v.end(), ostream_iterator<int>(cout, " ")); cout << endl;
   v.erase(v.begin() + 3, v.end() - 2);
   copy(v.begin(), v.end(), ostream_iterator<int>(cout, " ")); cout << endl;
   return 0;
}

/* my output
10 20 30 40 50 60 70 80 90 100
10 20 30 90 100
*/
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.