赋值操作
函数原型:
代码语言:javascript复制#include<iostream>
using namespace std;
#include<deque>
//deque的赋值操作
void p(const deque<int>& d)
{
for (deque<int>::const_iterator it = d.begin(); it != d.end(); it )
{
//*it = 100; 加了const关键字后,就无法对数据进行修改
cout << *it << " ";
}
cout << endl;
}
void realApply()
{
//1.尾插赋值
deque<int>d1;
d1.push_back(5);
d1.push_back(2);
d1.push_back(0);
p(d1);
//2.operator=赋值
deque<int> d2;
d2 = d1;
p(d2);
//3.assign赋值
deque<int> d3;
d3.assign(d2.begin(), d2.end());
p(d3);
//4.assign赋值
deque<int> d4;
d4.assign(5, 521);
p(d4);
}
int main()
{
realApply();
system("pause");
return 0;
}