Simple question, Please answer

Hello! Considering that Deduct is a vector...
Why does putting an "=" in the test expression not work when testing with a vector.size?
 
for (int i = 0; i <=Deduct.size(); ++i)
say your vector has 10 elements.

When you say "<=", the last element it will check is Deduct[10], which is very bad as only Deduct[0] to Deduct[9] elements exists.

Remember that indexing into a vector/array/collection is zero-based.
Valid subscripts are in the range 0 to size()-1
If you put i <=Deduct.size() then i is exceeding the range, and the code will attempt to access a non-existent element of the vector.,
Oh I forgot. Thanks!
Topic archived. No new replies allowed.