Hi guys, i am creating a somekind of rpg battle, where the program reads the input from a .txt file. i created the code but when i want to start the battle, it gave me an error vector subscript out of range. can anyone help me how to fix this? thank you very much :) here is the code
and so that we are on the same track, the content of the txt file for lamanite is
warrior (int h, int r);
int getDamage() const;
void takeDamage(int damage);
int getCurrentHP() const;
string tostring(int h, int r);
Im not familiar with using the "&" the way you did in line 63, but im gonna go ahead and say rL is bigger than lamanites.size(), and so lamanites[rL] does not exist, so the vector subscript rL IS out of range.
You use erase within the inner while loop. erase removes elements from the vector. Removing elements from the vector reduces the size of the vector.
rN and rL were selected with vectors of a certain size in mind. They are not reselected when the size of the vectors are reduced, therefore they may be out of bounds when the size of the vectors are reduced.