Resize function in STL Vector

When I searching for resize function of the STL Vector, I find some of the words says that this function may change or delete some members in my vector or add some new members.

I just want to ask:
1.which member will be delete if the vector's size less than n?
2.what is the initialize value of the new members if I don't give the pramater "val"?

no code yet
From cppreference https://en.cppreference.com/w/cpp/container/vector/resize

If the current size is greater than count, the container is reduced to its first count elements.

If the current size is less than count,
1) additional default-inserted elements are appended
2) additional copies of value are appended.
Hello VoidWalker,

For question 1: If you resize down it removes what is at the end.

For question 2: Leaving out a value for "val" it will use the default value based on the vectors type. (0) zero for "int" types, (\0) for "char"s, (0.0) for floating point types and a std::string would be empty.

Andy
You might also be interested in the reserve() method, which reserves space for more items, but without actually constructing them. This is handy if your intention is to make room for a lot of items that you'll insert later.
http://www.cplusplus.com/reference/vector/vector/reserve/
Thanks for reply.
Topic archived. No new replies allowed.