[ Web Proxy ]
URL:
Viewing: https://cs.cppreference.com/cpp/container/vector/push_back [Back]  [Original]

std::vector::push_back cppreference.com
cppreference.com
Jmenn prostory
Varianty

std::vector::push_back

Z cppreference.com
<tbody> </tbody>
void push_back( const T& value );
(1)
void push_back( T&& value );
(2) (ponaje C++11)

Pid dan prvek value na konec kontajneru.

1) Nov prvek je inicializovan jako kopije value.
2) value je pesunut do novho 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.

Parameters

value - hodnota pidvanho prvku
Poadavky kladen na typ
-
T mus splovat poadavky konceptu CopyInsertable in order to use overload (1).
-
T mus splovat poadavky konceptu MoveInsertable in order to use overload (2).

Return value

(none)

Complexity

Amortized constant.

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. (ponaje C++11)

Example

Nsledujc kd pouv push_back k pidn nkolika celoselnch 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';
    } 

    return 0;
}

Vstup:

42
314159

See also a

pid, konstruuje prvek pmo na konci vektoru
(veejn lensk funkce) [edit]
odstran posledn prvek
(veejn lensk funkce) [edit]

ablona:langlinks


Web Proxy Viewer  |  New URL  |  Original Page