deque容器05之[]和at读取元素

2021-03-02 17:02:03 浏览数 (1)

[]和at读取元素

函数原型:

代码语言:javascript复制
#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;
}

0 人点赞