C ++ Deque begin()函数返回一个指向deque容器第一个元素的迭代器。如果容器为空,则返回的迭代器将等于end()。
iterator begin();
它不包含任何参数。
它返回指向第一个元素的迭代器。
让我们看一个简单的实例
#include <iostream>
#include<deque>
using namespace std;
int main()
{
deque<int> n={1,2,3};
deque<int>::iterator itr;
itr=n.begin();
cout<<"first element of the deque:"<<*itr;
return 0;
}输出:
first element of the deque:1
在此示例中,begin()函数返回第一个元素的迭代器。
让我们看一个简单的实例
#include <iostream>
#include<deque>
using namespace std;
int main()
{
deque<char> ch={'C','+','+'};
deque<char>::iterator itr;
itr=ch.begin()+2;
cout<<*itr;
return 0;
}在此示例中,begin()函数递增2。因此,begin()函数返回第三个元素的迭代器。