Jmenné prostory
Varianty

std::vector::push_back

Z cppreference.com
void push_back(const T& value );
(1)
void push_back( T&& value );
(2) (počínaje C++11)

Přidá daný prvek value na konec kontajneru.

1) Nový prvek je inicializovaný jako kopije value.
2)value je přesunutý do nového prvku.

If the new size() is greater than capacity() then all iterators and references (including the past-the-end iterator) are invalidated. Otherwise only the past-the-end iterator is invalidated.

Obsah

[editovat]Parameters

value - hodnota přidávaného prvku
Požadavky kladené na typ
-
T musí splňovat požadavky konceptu CopyInsertable in order to use overload (1).
-
T musí splňovat požadavky konceptu MoveInsertable in order to use overload (2).

[editovat]Return value

(none)

[editovat]Complexity

Amortized constant.

[editovat]Exceptions

If an exception is thrown, this function has no effect (strong exception guarantee).

If T's move constructor is not noexcept and the copy constructor is not accessible, vector will use the throwing move constructor. If it throws, the guarantee is waived and the effects are unspecified.(počínaje C++11)

[editovat]Example

Následující kód používá push_back k přidání několika celočíselných prvků do std::vector<int>:

#include <vector>#include <iostream>   int main(){ std::vector<int> numbers;   numbers.push_back(42); numbers.push_back(314159);   for(int i : numbers){// c++11 range-based for loop std::cout<< i <<'\n';}   return0;}

Výstup:

42 314159

[editovat]See also a

přidá, konstruuje prvek přímo na konci vektoru
(veřejná členská funkce)[edit]
odstraní poslední prvek
(veřejná členská funkce)[edit]

Šablona:langlinks

close