Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

vector::cend

Returns a const iterator that addresses the location just beyond the last element in a range.

const_iterator cend() const;

A const random-access iterator that points just beyond the end of the range.

cend is used to test whether an iterator has passed the end of its range.

You can use this member function in place of the end() member 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 of any kind that supports end() and cend().

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

The value returned by cend should not be dereferenced.

Header: <vector>

Namespace: std

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.