+ 1

How to use erase w/ C++'s vectors

I have a "struct tir int x,y struct alien int x,y" And i made vectors of tirs and aliens but i dint now what to write in aliens.erase(????) to remove a specific one, can you help me?

19th Nov 2019, 12:53 PM
Axel Patron
Axel Patron - avatar
5 Respostas
+ 4
~ swim ~ Small correction, since the vec.erase returns the next valid iterator, you probably don't want to increment it again with the ++it when you reach the end of the body. Erasing the last element in this case would crash the program. Probably want to move the ++it to an else block.
19th Nov 2019, 2:03 PM
Dennis
Dennis - avatar
+ 4
~ swim ~ Can't blame you there, this happens to me pretty much every time as well. :)
19th Nov 2019, 2:09 PM
Dennis
Dennis - avatar
19th Nov 2019, 12:58 PM
Axel Patron
Axel Patron - avatar
+ 1
It's at line 86
19th Nov 2019, 12:58 PM
Axel Patron
Axel Patron - avatar
+ 1
I dont understand, can you fill? for(tir& t : tirs)     for(alien& a : aliens)         if(t.x>a.x && t.x<a.x+60 && t.y>a.y && t.y<a.y+60) "Erase the aliens shots"
19th Nov 2019, 2:16 PM
Axel Patron
Axel Patron - avatar