deque::cbegin

deque::cbegin is used to return a const iterator pointing to the first element in the container. We cannot use this to modify the contents the iterator points to.

Syntax:

const_iterator cbegin();

Parameters: None

Return Value: A const_iterator to the beginning of the sequence.

Iterator Validity: There is no change in Iterator Validity

Header File:

<deque>

Exceptions: It never throws exceptions

Example:

C++




// C++ program to demonstrate deque::cbegin
  
#include <deque>
#include <iostream>
using namespace std;
  
// Driver code
int main()
{
    // Declaration of Deque
    deque<int> GFG = { 1, 2, 3, 4, 5 };
  
    cout << "Elements in Deque Container are : ";
    for (auto it = GFG.cbegin(); it != GFG.cend(); ++it) {
        cout << *it << " ";
    }
    cout << endl;
    return 0;
}


Output:

Elements in Deque Container are : 1 2 3 4 5 
  • Time Complexity – O(1)
  • Space Complexity – O(1)

Difference Between deque::cbegin and deque::assign in C++

Deque or Double-ended queues are sequence containers with the feature of expansion and contraction on both ends. They are similar to vectors, but are more efficient in the case of insertion and deletion of elements at the end, and also the beginning. Unlike vectors, contiguous storage allocation may not be guaranteed. Here we will see the difference between deque::assign and deque::at in C++.

Similar Reads

deque::cbegin

deque::cbegin is used to return a const iterator pointing to the first element in the container. We cannot use this to modify the contents the iterator points to....

deque::assign

...