C++教程
C++控制语句
C++函数
C++数组
C++指针
C++对象
C++继承
C++多态
C++抽象
C++常用
C++ STL教程
C++迭代器
C++程序

C++ Deque begin()

C++ Deque begin()

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

语法

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

示例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()函数将返回第三个元素的迭代器。

昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4