C++ String cend
This function provides a pointer to the final character within the string.
Difference b/w end and cend
The sole contrast between end and cend function lies in the fact that cend yields a constant iterator indicating the constant value.
Syntax
Consider a string str. Syntax would be:
str.cend();
Parameter
This function does not contain any parameter.
Return value
This function provides the reference to the final element of the string.
Example 1
#include<iostream>
using namespace std;
int main()
{
string str ="mango is my favorite fruit";
fot(auto i=str.cbegin();i!=str.cend();i++)
{
cout<<*i;
}
return 0;
}
Output:
mango is my favorite fruit
This instance showcases the string through the utilization of the cbegin method.
Example 2
#include<iostream>
using namespace std;
int main()
{
list<int> li(1,2,3,4,5);
for(auto i=li.cbegin();i!=cend();++i)
cout<<*i
}
Output:
This example demonstrates the list utilizing the cbegin and cend functions.