0

Why is this vector out of bounds?

Please explain https://code.sololearn.com/cbsOBpT5I4kv/?ref=app

19th Mar 2020, 1:47 PM
TeaserCode
3 Respuestas
+ 3
On line 13 - 14: for (int i = 0; i <= SIZE; i++) a.at(i) = 8; You should use < not <= If you try to access elements at index < 0 or index >= a.size() at method throws std::out_of_range exception
19th Mar 2020, 1:51 PM
🇮🇳Omkar🕉
🇮🇳Omkar🕉 - avatar
+ 2
Problem's here: for (int i = 0; i <= SIZE; i++) Because you use <=, you also ask for a[3] which doesn't exist.
19th Mar 2020, 1:52 PM
HonFu
HonFu - avatar