Simple question, Please answer

Aug 1, 2014 at 11:42am
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)
Aug 1, 2014 at 11:52am
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.
Aug 1, 2014 at 11:52am
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.,
Aug 1, 2014 at 11:55am
Oh I forgot. Thanks!
Topic archived. No new replies allowed.