Can anybody tell me how to increment the iterator by 2?
iter++ is available - do I have to do iter+2? How can I achieve this?
We can use both std::advance as well as std::next, but there's a difference between the two.
advance modifies its argument and returns nothing. So it can be used as:
vector v;
v.push_back(1);
v.push_back(2);
auto itr = v.begin();
advance(itr, 1); //modifies the itr
cout << *itr<
next returns a modified copy of the iterator:
vector v;
v.push_back(1);
v.push_back(2);
cout << *next(v.begin(), 1) << endl; //prints 2