std::back_inserter_C++中文网
| 定义于头文件 |
||
| template< class Container > |
(C++20 前) | |
| template< class Container > |
(C++20 起) | |
back_inserter 为容器 c 构造 std::back_insert_iterator 的便利函数模板,拥有从参数类型推导的类型。
参数
返回值
能用于添加元素到容器 c 尾端的 std::back_insert_iterator 。
可能的实现
示例
#include <iostream> #include <vector> #include <algorithm> #include <iterator> int main() { std::vector<int> v{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; std::fill_n(std::back_inserter(v), 3, -1); for (int n : v) std::cout << n << ' '; }
输出:
1 2 3 4 5 6 7 8 9 10 -1 -1 -1