std::vector::push_back
来自cppreference.com
|
|
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
| void push_back( const T& value ); |
||
| void push_back( T&& value ); |
(C++11 起) | |
定元素追加
value所述容器的端部. 原文:
Appends the given element
value to the end of the container. If the new size() is greater than capacity(), all iterators and references are invalidated. Otherwise no iterators and references are invalidated.
目录 |
[编辑] 参数
| value | - | 要追加的元素的值
|
[编辑] 要求
1) 2)[编辑] 返回值
(无)
[编辑] 复杂性
恒定
[编辑] 为例
下面的代码使用
push_back添加到std::vector<int>几个整数
原文:
The following code uses
push_back to add several integers to a 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; }
输出:
42 314159
[编辑] 另请参阅
| (C++11) |
在末端就地构造元素 (公共成员函数) |
| 删除最后一个元素 (公共成员函数) | |