Share via


array::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 array Class (TR1) or to the location succeeding an empty array. You should always compare the value returned with array::cend or array::end to ensure it is valid.

Remarks

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

Example

// array_cbegin.cpp
// compile with: /EHsc
#include <array>
#include <iostream>

int main()
{
    using namespace std;
    array<int, 2> c1 = {1, 2};
    array<int, 2>::const_iterator c1_Iter;

    cout << "The array 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 array c1 contains elements: 1 2

Requirements

Header: <array>

Namespace: std

See Also

Reference

<array>

array Class (TR1)

Standard Template Library

Other Resources

<array> Members