struggling to delete a vector element | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson

struggling to delete a vector element

So, i'm creating a HCF/LCM calculator using vectors, and when doing calculations, i try to remove certain elements once their no longer needed. however, when trying to do so, i am met with an "exit status -1" error. could someone help me understand why? the code: or, alternatively, use:

8th Jul 2018, 6:02 PM
X-1 - avatar
2 Answers
+ 1
Because the iterator is invalid. At the first iteration of the nested for loop x = 0 Then you do num2.begin() + -1 which results an invalid iterator. Kinda like doing num2[-1] when accessing an array. It just so happens that you increment i by 1 before you start deleting otherwise the erase attempt of nums would fail as well.
8th Jul 2018, 6:40 PM
Dennis - avatar
X-1 Can you create in Code Playground the code and post his url? make in crysis my phone 😅
8th Jul 2018, 6:18 PM
KrOW - avatar