Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining


Retrieves a const iterator to the first element in a specified container.

template<class Container>
    auto cbegin(const Container& cont) 
        -> decltype(cont.begin());


A container or initializer_list.

A constant cont.begin().

This function works with all STL containers and with initializer_list.

You can use this member function in place of the begin() template function to guarantee that the return value is const_iterator. Typically, it's used in conjunction with the auto type deduction keyword, as shown in the following example. In the example, consider Container to be a modifiable (non-const) container or initializer_list of any kind that supports begin() and cbegin().

auto i1 = Container.begin();  // i1 is Container<T>::iterator
auto i2 = Container.cbegin(); // i2 is Container<T>::const_iterator

Header: <iterator>

Namespace: std

© 2015 Microsoft