C++ Deque 中的 begin()函数

首页 / C++入门教程 / C++ Deque 中的 begin()函数

C++ Deque begin()函数返回一个指向deque集合第一个元素的迭代器。如果集合为空,则返回的迭代器将等于end()。

begin - 语法

iterator begin(); 

begin - 返回值

它返回一个指向双端队列第一个元素的迭代器。

begin - 例子1

让我们看一个简单的例子

#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()函数返回第一个元素的迭代器。

begin - 例子2

让我们看一个简单的例子

无涯教程网

#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无涯教程网

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

微服务架构核心20讲 -〔杨波〕

软件测试52讲 -〔茹炳晟〕

如何设计一个秒杀系统 -〔许令波〕

代码精进之路 -〔范学雷〕

玩转Git三剑客 -〔苏玲〕

Node.js开发实战 -〔杨浩〕

计算机基础实战课 -〔彭东〕

AI绘画核心技术与实战 -〔南柯〕

徐昊 · AI 时代的软件工程 -〔徐昊〕

好记忆不如烂笔头。留下您的足迹吧 :)