STL 关于find()


用find()可以,?STL的string提供七种参数形式的find(),如果你可以确定你要查找的字符串靠后或者同时有多个子字符串符合,应该使用rfind()系列或者find_last_of()系列函数来查找,STL的string提供了100个以上的操作函数,五个find()函数原型及简单说明:
(1)size_type string::find(char c) const;
(2)size_type string::find(char c,size_type idx) const;
(3)size_type string::find(const string& str) const;
(4)size_type string::find(const string& str,size_type idx) const;
(5)size_type string::find(const char* cstr) const;
(6)size_type string::find(const char* cstr,size_type idx) const;
(7)size_type string::find(const char* cstr,size_type idx,size_type chars_len) const;
说明:
1>.以上函数如果查找失败返回string::npos,如果成功:
函数(1)返回从头开始的第一个字符所在位置
函数(2)返回从idx开始的第一个字符所在位置
函数(3)返回从头开始的第一个子字符串所在位置
函数(4)返回从idx开始的第一个子字符串所在位置
函数(5)返回从头开始的与char*串相等的第一个子串所在位置
函数(6)返回从idx开始的与char*串相等的第一个子串所在位置
函数(7)返回从idx开始的与char*串前chars_len个字符相等的第一个子串所在位置

string str;
std:size_type idx = st.find("c");
if( std::string::npos != idx )
{
//查找成功,加入处理步骤
}
else
{
//没有找到时的处理
}


  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值