Ric*_*hez 1 c++ iterator vector
I have one vector container and I would like to make a subtraction operation on the values of its content using the current iterator against the previous iterator, any help will be much appreciated
vector<MyClass>::iterator itPrevious = my_vec.begin();
vector<MyClass>::iterator itCurrent = itPrevious;
if (itCurrent != my_vec.end())
{
for (++itCurrent; itCurrent != my_vec.end(); ++itCurrent)
{
// do something with itPrevious and itCurrent
itPrevious = itCurrent;
}
}
Run Code Online (Sandbox Code Playgroud)