Deque cbegin( ) in C++

In this tutorial, we will learn aboutĀ Deque cbegin() in C++.

Deque stands for Double Ended Queues which are sequence containers where you can insert or delete elements from both the ends. It is a special type of queue.

The functions for Deque are same as vectors in addition to insertion and deletion at both ends. Deques are much better and preferred for the insertion and deletion of elements than vectors.

Header File for deque is:

#include <deque>

Deque cbegin( ) function in C++

Deque cbegin() is a function in C++ that returns a constant iterator pointing to the first element of the deque container. This iterator can be incremented or decremented just like the iterator returned by the begin() function.
cbegin() function does not have any arguments in it.

The syntax for this function is:


Now let us write the codeĀ to illustrate the same.

#include <deque> 
#include <iostream> 
using namespace std; 
int main() 
  deque<int> dqe = { 65, 2, 31, 5, 9 };    // creation of deque
  cout<<"First element of the deque is: "; 
  cout<<*dqe.cbegin();               // returns first element of deque


First element of the deque is: 65


In this code, first of all, the header file <deque> contains all the functions of the deque. We declared the deque having some values in it. Then, we print the first element of the deque using the function cbegin( ), where cbegin( ) is used to return the first element of the list.

I hope you can try this to solve your problem.

You can also read:

Sort a vector of pairs in C++

Implementing a Vector as a stack in C++


Leave a Reply

Your email address will not be published. Required fields are marked *