std::vector::push_back
Материал из cppreference.com
|
|
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
| void push_back( const T& value ); |
||
| void push_back( T&& value ); |
(начиная с C++11) | |
Добавляет данный элемент
value до конца контейнера. Original:
Appends the given element
value to the end of the container. The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
If the new size() is greater than capacity(), all iterators and references are invalidated. Otherwise no iterators and references are invalidated.
Содержание |
[править] Параметры
| value | - | Значение элемента для добавления
Original: the value of the element to append The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
[править] Требования
1)value должны быть CopyInsertableOriginal:
value shall be CopyInsertableThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
value должны быть MoveInsertableOriginal:
value shall be MoveInsertableThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[править] Возвращаемое значение
(Нет)
Original:
(none)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[править] Сложность
Постоянное.
Original:
Constant.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[править] Пример
Следующий код использует
push_back добавить несколько целых чисел std::vector<int>
Original:
The following code uses
push_back to add several integers to a std::vector<int>:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
#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; }
Вывод:
42 314159
[править] См. также
| (C++11) |
Элементы конструкций на месте в конце Original: constructs elements in-place at the end The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (public функция-член) |
| удаляет последний элемент Original: removes the last element The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (public функция-член) | |