C++ Deque clear()函数从双端队列中删除所有元素,并且双端队列的大小减小为零。
void clear();
它不返回任何值。
让我们看一个简单的例子
#include <iostream> #include<deque> using namespace std; int main() { deque<int> first; deque<int>::iterator itr; cout<<"Content of first deque:"; first.push_back(1); first.push_back(2); first.push_back(3); for(itr=first.begin();itr!=first.end();++itr) cout<<*itr<<" "; cout<<'\n'; first.clear(); cout<<"Now,Content of first deque:"; first.push_back(4); first.push_back(5); first.push_back(6); for(itr=first.begin();itr!=first.end();++itr) cout<<*itr<<" "; return 0; }
输出:
Content of first deque:1 2 3 Now,Content of first deque:4 5 6
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)