back_insert_iterator::operator=
追加或被推入容器的后端的上一个值。
back_insert_iterator<Container>& operator=(
typename Container::const_reference _Val
);
back_insert_iterator<Container>& operator=(
typename Container::value_type&& _Val
);
参数
- _Val
要插入的值到容器中。
返回值
对最后的元素引用插入在容器的值。
备注
第一成员运算符计算 Container.push_back(_Val),
然后返回 *this。 第二个成员运算符计算
container->push_back((typename Container::value_type&&)val),
然后返回 *this。
示例
// back_insert_iterator_op_assign.cpp
// compile with: /EHsc
#include <iterator>
#include <vector>
#include <iostream>
int main( )
{
using namespace std;
int i;
vector<int> vec;
for (i = 1 ; i < 4 ; ++i )
{
vec.push_back ( i );
}
vector <int>::iterator vIter;
cout << "The vector vec is: ( ";
for ( vIter = vec.begin ( ) ; vIter != vec.end ( ); vIter++)
cout << *vIter << " ";
cout << ")." << endl;
back_insert_iterator<vector<int> > backiter ( vec );
*backiter = 10;
backiter++; // Increment to the next element
*backiter = 20;
backiter++;
cout << "After the insertions, the vector vec becomes: ( ";
for ( vIter = vec.begin ( ) ; vIter != vec.end ( ); vIter++)
cout << *vIter << " ";
cout << ")." << endl;
}
Output
The vector vec is: ( 1 2 3 ).
After the insertions, the vector vec becomes: ( 1 2 3 10 20 ).
要求
头文件: <iterator>
命名空间: std