C ++ Deque begin()函數(shù)返回一個指向deque容器第一個元素的迭代器。如果容器為空,則返回的迭代器將等于end()。
iterator begin();
它不包含任何參數(shù)。
它返回指向第一個元素的迭代器。
讓我們看一個簡單的實(shí)例
#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()函數(shù)返回第一個元素的迭代器。
讓我們看一個簡單的實(shí)例
#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()函數(shù)遞增2。因此,begin()函數(shù)返回第三個元素的迭代器。