This effectively increases the vector size by one, which causes a reallocation of the internal allocated storage if the vector size was equal to the vector capacity before the call. Reallocations invalidate all previously obtained iterators, references and pointers.
Parameters
- x
- Value to be copied to the new element.
T is the first template parameter (the type of the elements stored in the vector).
Return value
noneIf a reallocation happens, it is performed using Allocator::allocate(), which may throw exceptions (for the default allocator, bad_alloc is thrown if the allocation request does not succeed).
Example
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
|
The example uses push_back to add a new element to the vector each time a new integer is read.
Complexity
Constant (amortized time, reallocation may happen).See also
| vector::pop_back | Delete last element (public member function) |
| vector::insert | Insert elements (public member function) |
