TheDeveloperBlog.com

Home | Contact Us

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

C++ Vector crbegin() function

C++ Vector crbegin() 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 crbegin()

The crbegin() function stands for reverse beginning. It is used to point the last character of the vector container.

crbegin() vs rbegin()

The crbegin() function returns the constant reverse iterator while rbegin() function returns the reverse iterator. The element pointed by the rbegin() function can be modified but not by crbegin() function.

Syntax

Consider a vector 'v'. Syntax would be:

const_reverse_iterator itr=v.crbegin();

Parameter

It does not contain any parameter.

Return value

It returns constant reverse iterator pointing to the reverse beginning of the container.

Example 1

Let's see a simple example.

#include <iostream>
#include<vector>
using namespace std;
int main()
{
vector<int> v{100,200,300,400};
vector<int>::const_reverse_iterator itr=v.crbegin();
  *itr=500;
cout<<*itr;
return 0;}

Output:

Error

In this example, we are trying to modify the value using crbegin() function which is not possible in this case.

Example 2

Let's see another simple example.

#include <iostream>
#include<vector>
using namespace std;
int main()
{
vector<string> v{"Mango","banana","strawberry","kiwi"};
vector<string>::const_reverse_iterator itr=v.crbegin();
cout<<*itr;
return 0;
}

Output:

kiwi

In this example, crbegin() function is used to access the last element of the vector container.

Example 3

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_reverse_iterator itr=v.crbegin()+2;
cout<<*itr;
return 0;
}

Output:

3

In this example, crbegin() function is incremented by 2 to access the third element of the vector and this function access all the elements from backward.

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