首页 > 其他 > 详细

string中find()和substr()的用法

时间:2020-01-17 20:39:56      阅读:90      评论:0      收藏:0      [点我收藏+]

string中find()和substr()的用法

查找从指定位置开始的

string s="123453";
cout<<s.find('3')<<endl;
cout<<s.find('3',2);
输出:
2
2

当找不到的时候,函数会返回一个s.npos

找第一个目标字符串的位置和最后一个的位置(不是全匹配):

string s="123453";
cout<<s.find_first_of("34")<<endl;
cout<<s.find_last_of("54")<<endl;
输出:
2
4

在使用substr(pos,n)函数的时候一定要注意里面的参数,第一个是起点,第二个是长度!

string中find()和substr()的用法

原文:https://www.cnblogs.com/CADCADCAD/p/12207283.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!