1:可用迭代器
2:地址访问
#include <iostream> #include <string> #include <deque> //头文件不能少 using namespace std; deque<string> deq;//这里用一个string类型的deque来做演示,初始为空 deque<string>::iterator it; //提前准备一个迭代器,写法一如既往 int main() { deq.push_back("last string"); deq.push_front("front string"); for (it = deq.begin(); it != deq.end(); it++) { cout << *it << endl; } //遍历及输出元素 cout << endl; it = deq.begin(); it++; deq.insert(it, "middle"); //将字符加到队列中第2个位置 for (it = deq.begin(); it != deq.end(); it++) { cout << *it << endl; } cout << endl; deq.insert(deq.begin()+2, "test"); //将字符加到队列中第3个位置 for (it = deq.begin(); it != deq.end(); it++) cout << *it << endl; cout<<endl; deq.erase(deq.begin() + 1); //删除队列中第2个字符串 for (it = deq.begin(); it != deq.end(); it++) cout << *it << endl; return 0; }
标签:deque,string,定位,队列,双端,deq,front,include From: https://www.cnblogs.com/cutemush/p/17347645.html