vector::operator=
用另一个矢量的副本替换为个矢量的元素。
vector& operator=(
const vector& _Right
);
vector& operator=(
vector&& _Right
);
参数
Parameter |
说明 |
_Right |
复制到 vector的 vector Class。 |
备注
在清除在 vector的任何现有组件后,operator= 复制或移动 _Right 内容 vector。
示例
// vector_operator_as.cpp
// compile with: /EHsc
#include <vector>
#include <iostream>
int main( )
{
using namespace std;
vector<int> v1, v2, v3;
vector<int>::iterator iter;
v1.push_back(10);
v1.push_back(20);
v1.push_back(30);
v1.push_back(40);
v1.push_back(50);
cout << "v1 = " ;
for (iter = v1.begin(); iter != v1.end(); iter++)
cout << *iter << " ";
cout << endl;
v2 = v1;
cout << "v2 = ";
for (iter = v2.begin(); iter != v2.end(); iter++)
cout << *iter << " ";
cout << endl;
// move v1 into v2
v2.clear();
v2 = move(v1);
cout << "v2 = ";
for (iter = v2.begin(); iter != v2.end(); iter++)
cout << *iter << " ";
cout << endl;
}
Output
v1 = 10 20 30 40 50
v2 = 10 20 30 40 50
v2 = 10 20 30 40 50
要求
标头: <vector>
命名空间: std