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

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: https://repl.it/@NasirMuhammad/HCF-and-LCM-calculator or, alternatively, use: https://code.sololearn.com/cmF1wRAl0Evz

8th Jul 2018, 6:02 PM
X-1
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
Dennis - avatar
0
X-1 Can you create in Code Playground the code and post his url? Repl.it make in crysis my phone 😅
8th Jul 2018, 6:18 PM
KrOW
KrOW - avatar