Actually it works just fine except that, in your example, vec[0]
has been changed to 1
after the first run, which makes the remaining runs look like "not working" (remain the same value if divided by 1
).
You will see it clearly by using the following example (will work "as expected"):
vector<float> vec = { 1, 2, 3, 4, 5 };
for (auto &elem : vec){
elem /= vec[4];
}
// now vec={0.2, 0.4, 0.6, 0.8, 1.0}