C++ String end
This function is used to return an iterator pointing to the last character of the string.
Syntax
Consider a string 'str' and an iterator 'it'. Syntax would be:
Example
iterator it = str.end();
Parameter
This function does not contain any parameter.
Return value
It returns an iterator pointing to the end of the string.
Example 1
Let's see the simple example.
Example
#include<iostream>
#include<string>
using namespace std;
int main()
{
string str="Java is an object oriented programming language";
string::iterator it =str.end();
cout<<*(it-1);
return 0;
}
Output:
Example 2
Let's see an another simple example.
Example
#include<iostream>
using namespace std;
int main()
{
string str="Welcome to javaCppTutorial";
for(string::iterator itr=str.begin();itr!=str.end();++itr)
cout<<*itr;
return 0;
}
Output:
Output
Welcome to javaCppTutorial