C++ deque begin() Function
Example
Get the first element of a deque with an iterator:
deque<string> cars = {"Volvo", "BMW", "Ford", "Mazda"};
deque<string>::iterator it = cars.begin();
cout << *it;
Definition and Usage
The begin() function returns an iterator (an object that points to an element, similar to a pointer). It points to the first element of the deque. Use * to get the value of the element.
begin() is often used together with end() to loop through a deque.
The begin function is defined in the <deque> header file.
Tip: Learn more about iterators in our Iterators chapter.
Syntax
deque.begin();
Parameter Values
None.
Technical Details
| Returns: | An iterator pointing to the first element of the deque. |
|---|
Related Pages
Read more about deques in our Deque Tutorial.