Given the task is to show the working of deque::cbegin() in C++ STL.
deque::cbegin() is a function which comes under deque header file, cbegin() returns the iterator pointer which points to the first element of the deque container.
Note − cbegin() function does not have any arguments in it.
deq.cbegin();
Where deq is the deque’s object.
The function returns a const_iterator.
const_iterator is a random access iterator which is used to point to the first element of the deque container. We can traverse the whole container using the first element of the container, but this can’t be used to do the modifications in the container’s value, but can print the whole container.
#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 }
If we run the above code it will generate the following output −
First element of the deque is: 65
In this code, 1st of all, the header file contains all the functions of the deque. we have a tendency to declare the deque having some values in it. Then, we have a tendency to print the primary component of the deque exploitation the perform cbegin( ), wherever cbegin( ) is employed to return the primary component of the list.