c++ string类的find:
1.find

string s = "My cat's breath smells like cat food.";
int a=s.find("breath");
cout<<a<<endl;

因为find是从0数起,输出字符串第一个字符的索引(从0开始),所以a为9

2.rfind

string s = "My cat's breath smells like cat food.";
int a=s.rfind("breath");
cout<<a<<endl;

因为rfind是从后部数起,还是输出字符串第一个字符的索引(从0开始)

其实,find与rfind一样,都可以找完整的字符串和字符,下面来看看另外一些奇葩的函数

3.find_first_of

string s = "My cat's breath smells like cat food.";
int a=s.find_first_of("beah");
cout<<a<<endl;

从0数起,但它只需找到一个与它串里一样的字符就输出来了
答案是:4
4.find_last_of

string s = "My cat's breath smells like cat food.";
int a=s.find_last_of("beah");
cout<<a<<endl;

从后部数起,而且和find_first_of一样,输出最后一个有一样的就好了
答案是: 29

5.find_first_not_of

string s = "aaabaaaaaabaa.";
int a=s.find_first_not_of('a');
cout<<a<<endl;

从0数起,但它只需找到一个与它串里不一样的字符就输出来了
答案是:3

6.find_last_not_of

string s = "aaabaaaaaabaa";
int a=s.find_last_not_of('a');
cout<<a<<endl;

从后部数起,而且和find_first_not_of一样,也是输出第一个(似乎是最后一个哈)有一样的就好了
答案是: 10

如果没找到的话会输出string::npos

最新文章

  1. Netron源码解读(一):GraphControl画布对象
  2. python 之sqlalchemy many to one
  3. NYOJ之字符串逆序输出
  4. 找模式串[XDU1032]
  5. 如何让JS的变量名变量化
  6. C#winform修改IP,dns
  7. Python基础篇-day5
  8. Spring Boot 实现 RabbitMQ 延迟消费和延迟重试队列
  9. 移动端web自适应适配布局解决方案
  10. React-Native采坑总结
  11. xlua build时 报错处理
  12. PCIe传输速率和可用带宽(吞吐量)计算
  13. SCRUM管理之KPI与OKRs结合
  14. paloalto防火墙注册
  15. java发送163邮件
  16. SRCNN
  17. Winfrom窗体无法关闭问题--检查是否存在重写
  18. C语言 &#183; 身份证排序
  19. 【BZOJ4184】shallot 线性基
  20. Maven 上传本地包到仓库 (来源于同事(gagahjt)的笔记本)

热门文章

  1. MongoDB快速入门教程 (4.1)
  2. 微信开发_Exception_02_&quot;errcode&quot;:40164,&quot;errmsg&quot;:&quot;invalid ip 61.172.68.219, not in whitelist hint
  3. centos6.4 卸载 vim7.2 安装vim7.4
  4. python数据类型的72变
  5. lombok使用指南,代码极简工具
  6. 用Python语言绘制股市OBV指标效果
  7. 一文搞定 Spring Data JPA
  8. 一道题理解setTimeout,Promise,async/await以及宏任务与微任务
  9. Bootstrap 搭建基础页面
  10. JVM 专题十九:垃圾回收(三)垃圾回收相关概念