hmm . so that's y i got run time error ?
So , i need to resize vector after removing element ?
That depends on what you're trying to accomplish.
Only one thing is for certain: don't try to access the second element of a vector that has less than two elements.
but i am removing 1st element in the vector. so why have run time error ? i think after removing i need to resize .but i checked many people example . they didnot resized it .
When you remove the first element, then vec will become vec. The vector size is now down to 1 and there isn't a vec anymore.
When an element is erased, the size of the vector changes. It's not that you need to resize it, it's that the container is resized for you.
If, originally, your vector has a size of 2 a couple things happen when you erase the first element:
The first element is destroyed.
The 2nd element is moved to the former first element's position.
The vector is resized.
So, what was formerly at velleys is now at velleys, and velleys is no longer a valid way to access the vector.
yes i understand, but why my program crash then ? if velleys is no longer exist then it should not make any problem.
It is a problem if you're trying to access velleys again.
There's not enough context to determine what's causing your code to crash. Not respecting the new size of the vector was simply the most likely candidate.
Oh ok ,i catched my bug .
" It is a problem if you're trying to access velleys again. "
You are right , i am code . i did that.
I found it just after reading your comment . thanks . :)
And tanks cire too .. :)
OK SOLVED :)
THANKS BOTH OF YOU. :)
Last edited on