TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

C++ Vector cend() function

C++ Vector cend() function tutorial for beginners and professionals with examples on assign(), at(), back(), begin(), capacity(), cbegin(), cend(), clear(), crbegin(), crend(), data(), emplace(), end(), front(), rbegin(), resize(), size(), swap() etc.

<< Back to CPP

C++ Vector cend()

This function is used to point to the past-the-last element (element after the last element) in the vector.

cend() vs end()

The cend() function returns the constant iterator while end() function returns an iterator. The element pointed by the end() functioncan be modified but not by the cend() function.

Syntax

Consider a vector 'v', Syntax would be:

const_iterator itr=v.cend();

Parameter

It does not contain any parameter.

Return value

It returns a constant iterator pointing to thepast-the-last element in the vector.

Example 1

Let's see 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, cend() function is accessed using an object of constant iterator type.

Example 2

Let's see 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
Next TopicC++ Vector




Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf