此函数用于返回指向字符串最后一个字符的迭代器。
iterator it = str.end();
它返回一个指向字符串末尾的迭代器。
链接:https://www.learnfk.comhttps://www.learnfk.com/c++/cpp-string-end-function.html
来源:LearnFk无涯教程网
让我们看一个简单的例子。
#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; }
输出:
e
让我们来看另一个简单的例子。
#include<iostream> using namespace std; int main() { string str="Welcome to learnfk"; for(string::iterator itr=str.begin();itr!=str.end();++itr) cout<<*itr; return 0; }
输出:
Welcome to learnfk
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)