deque容器05之[]和at讀取元素
阿新 • • 發佈:2021-02-10
技術標籤:stl學習之dequec++stl
[]和at讀取元素
函式原型:
#include<iostream>
using namespace std;
#include<deque>
//deque的元素讀取操作
void realApply()
{
deque<int>d1;
d1.push_back(0);
d1.push_front(2);
d1.push_front(5);
//[]
for (int i = 0; i < d1.size(); i++)
{
cout << d1[i] << " " ;
}
cout << endl;
//at
for (int i = 0; i < d1.size(); i++)
{
cout << d1.at(i) << " ";
}
cout << endl;
cout << "返回容器中第一個元素: " << d1.front() << endl;
cout << "返回容器中最後一個元素: " << d1.back() << endl;
}
int main()
{
realApply();
system("pause");
return 0;
}