Share via


basic_string::cend

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

const_iterator cend() const;

Return Value

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

Remarks

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.

Requirements

Header: <string>

Namespace: std

See Also

Reference

basic_string Class

<string>