English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
This function is used to point to the last element in the vector (vector).
cend() returnsa constant iteratorwhile the end() function returnsIterator.end() functionthe element pointed tocan be modifiedButcend() functionCannotModification.
Consider the vector (vector) 'v', the syntax is:
const_iterator itr = v.cend();
It does not contain any parameters.
It returns a constant iterator pointing to the last element in the vector (vector).
Let's look at a simple example.
#include iostream #include<vector> using namespace std; int main() { vector<char> v{'T','u','t','o','r','i','a','l'}; vector<char>::const_iterator citr; for(citr = v.cbegin(); citr != v.cend(); citr++) std::cout <<*citr; return 0; }
Output:
Tutorial
In this example, the cend() function is accessed using an object of the constant iterator type.
Let's look at a simple example.
#include iostream #include<vector> using namespace std; int main() { vector<int> v{1,2,3,4,5}; vector<int>::const_iterator citr; for(citr = v.cbegin(); citr != v.cend(); citr++) std::cout <<*citr << " "; return 0; }
Output:
1 2 3 4 5