描述:
构造向尾端插入的插入迭代器,可以通过该迭代器对容器插入元素。
函数定义:
template< class Container >
std::back_insert_iterator<Container> back_inserter( Container& c );
template< class Container >
constexpr std::back_insert_iterator<Container> back_inserter( Container& c );
参数:
c - 支持 push_back 操作的容器
返回值:
返回能用于添加元素到容器 c 尾端的 std::back_insert_iterator 。
可能的实现:
template< class Container >
std::back_insert_iterator<Container> back_inserter( Container& c )
{
return std::back_insert_iterator<Container>(c);
}
示例:
#include <iostream>
#include <iterator>
#include <string>
int main(int argc, char **argv)
{
std::string s1 = "4258613597";
std::string s2 = "hello";
std::copy(s1.begin(), s1.end(), std::back_inserter(s2));
std::cout << s2 << std::endl;//hello4258613597
return 0;
}