English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
C++ Deque (Double-ended Queue)
C ++ The cbegin() function of Deque returns a constant iterator that points to the first element of the deque container. This iterator can be incremented or decremented, just like the iterator returned by the begin() function. If the container is empty, the iterator returned will be equal to cend().
const_iterator cbegin();
It does not contain any parameters.
It returns a constant iterator pointing to the beginning of the container.
Let's look at a simple example
#include <iostream> #include<deque> using namespace std; int main() { deque<string> fruit = {"mango", "apple", "banana", "kiwi"}; deque<string>::const_iterator itr; itr = fruit.cbegin(); cout<<*itr; return 0; }
Output:
mango
In this example, the cbegin() function returns a constant iterator to the beginning of the container.
Let's look at a simple example
#include <iostream> #include<deque> using namespace std; int main() { deque<int> k={100,200,300,400,500}; deque<int>::const_iterator itr; itr=k.cbegin()+3; cout<<*itr; return 0; }
Output:
400
In this example, the cbegin() function increments3. Therefore, it returns the4An iterator for each element.