Partager via


deque::cbegin

Returns a const random-access iterator to the first element in the container.

const_iterator cbegin() const;

Return Value

A const random-access iterator addressing the first element in the deque Class or to the location succeeding an empty deque. You should always compare the value returned with deque::cend or deque::end to ensure it is valid.

Remarks

With the return value of deque::cbegin, the deque object cannot be modified.

Example

// deque_cbegin.cpp
// compile with: /EHsc
#include <deque>
#include <iostream>

int main()
{
    using namespace std;
    deque<int> c1;
    deque<int>::const_iterator c1_Iter;

    c1.push_back(1);
    c1.push_back(2);

    cout << "The deque c1 contains elements:";
    c1_Iter = c1.cbegin();
    for (; c1_Iter != c1.cend(); c1_Iter++)
    {
        cout << " " << *c1_Iter;
    }
    cout << endl;

    // The following line would be an error because iterator is const
    // *c1.cbegin() = 200;
}
The deque c1 contains elements: 1 2

Requirements

Header: <deque>

Namespace: std

See Also

Reference

deque Class

Standard Template Library

Other Resources

deque Class Members