cend(): It returns a read-only (constant) iterator that points one past the
last character in the given string.
This function is available in the below file
File: basic_string.h
Parameter: No parameters are required for this function.
Syntax:
string ::const_iterator it = str.cend()
For Example:
str = "abc"
str.cend() = > It points to the beyond the last character of the string (i.e beyond c). To print the last character we need to subtract one from this iterator.
Approach
C++
#include <bits/stdc++.h>using namespace std;int main(){string str = "abc";string ::const_iterator it = str.cend();cout << *(it - 1) << "\n";return 0;}
No comments:
Post a Comment