C++ String end()
C++ String end()
此函数用于返回指向字符串最后一个字符的迭代器。
语法
考虑一个字符串" str"和一个迭代器" it"。语法为:
参数
此函数不包含任何参数。
返回值
它返回一个迭代器
示例1
让我们看一个简单的示例。
#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;
}
输出:
示例2
让我们看另一个简单的示例。
#include<iostream>
using namespace std;
int main()
{
string str="Welcome to lidihuo";
for(string::iterator itr=str.begin();itr!=str.end();++itr)
cout<<*itr;
return 0;
}
输出: