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()函数返回第三个元素的迭代器。
链接:https://www.learnfk.comhttps://www.learnfk.com/c++/cpp-deque-begin-function.html
来源:LearnFk无涯教程网
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)