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
2 Antworten
+ 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.
0
X-1 Can you create in Code Playground the code and post his url?
Repl.it make in crysis my phone 😅