|
vector::push_backpublic member function
void push_back ( const T& x ); Add element at the end Adds a new element at the end of the vector, after its current last element. The content of this new element is initialized to a copy of x.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
Return valuenoneIf 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
The example uses push_back to add a new element to the vector each time a new integer is read. ComplexityConstant (amortized time, reallocation may happen).See also
|