using vectors: how change the last item?

how can i change the last item on a vector?
VarNames[VarNames.size()-1].Type ="test";
'VarNames' is a vector. my problem is how can i change the 'Type' member on last vector item.
that line give me a runtime error... so what i'm doing wrong?
That is a valid way to change the last element. We need more context.

vector.back() is a simpler way to do the same thing:
VarNames.back().Type = "test";

If VarNames.size() == 0, you are trying to access VarNames[-1],
which becomes VarNames[maximum size_t value], which is going out of bounds of your vector.
Last edited on
i did for test... but on runtime i get an error:
"Process returned -1073741819 (0xC0000005) execution time : 1.748 s
Press any key to continue."
if i comment that line, i will not get that exit error
Last edited on
The size of your vector is probably 0.
Ganado true and i found 2 problems:
1 - the added value type was wrong;
2 - i forget added the item on vector on another 'if'.
thank you so much for all
Topic archived. No new replies allowed.