利用拷贝赋值操作符(深复制)
vector array{
3,5,2,6,4};
vector outarray;
outarray = array;
vector array{
3,5,2,6,4};
vector outarray(array);
会清空原vector数组
vector array{
3,5,2,6,4};
vector outarray;//设为空
outarray.swap(array);//清空array数组
vector array{
3, 5, 2, 6, 4};
vector outarray{
1,2,3 };
outarray.swap(array);//outarray={3,5,2,6,4};array={1,2,3}
vector array{
3, 5, 2, 6, 4};
vector outarray{
1,2,3 };
outarray.assign(array.begin(),array.end());//清空原数据,赋予新数据={3,5,2,6,4}
outarray.assign(5, 0);//5个0,清空原数据={0,0,0,0,0,}