cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
Beginners
Simple question, Please answer
Simple question, Please answer
Aug 1, 2014 at 11:42am UTC
nooblet001
(13)
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 UTC
mutexe
(2372)
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 UTC
Chervil
(7320)
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 UTC
nooblet001
(13)
Oh I forgot. Thanks!
Topic archived. No new replies allowed.