for loop iterator

Hi all!
What is wrong with this loop that have to increment each element in the vector?

vector<int>::iterator iter;
for (iter=scores.begin(); iter!=scores.end();++iter)
{
iter++
}

I think what is wrong is that it doesn't have the derefenrence operator (*) in front of iter++, so it doesn't increment the value of each element in the vector.
I want to make sure that i am correct.
Thank you in advance!
vector<int>::iterator iter;
for (iter=scores.begin(); iter!=scores.end();++iter)
{
iter++
}


There is an increment. Look at your for loop ++iter.

To de-reference it, you should just do a cout << *iter << "\n";

Or to use STL copy function copy(scores.begin(),scores.end(),ostream_iterator<int>(cout," "));
Assuming that what you are trying to do is to modify the vector by adding one to each value stored in it, then yes, you need the dereference operator.

(*iter)++;

The parenthesis are necessary because the postfix increment operator ++ has a higher precedence than the dereference operator *.
If you think STL algorithm can do a better job than your own crafted for loop, try below
http://www.cplusplus.com/reference/algorithm/for_each/

void myfunction (int i) {
++i;
}

for_each (scores.begin(), scores.end(), myfunction);
Yes, the idea was trying to modify the vector by adding one to each value stored in it.
So, it is right the (*iter)++
I didn't know about the parenthesis.

Thank you so much everybody
Topic archived. No new replies allowed.