find()函数返回类型:size_type

1/S.find(T):返回T在S中第一次匹配的下标位置

2/S.find_first_of(T):返回字符串T第一个字符在S中第一次出现的下标位置

3/S.find("T",2):从字符串S下标2开始,查找字符串“T”,返回在S中匹配的下标

4/T.find_first_not_of(S):查找T中第一个在S中找不到的字符在T中所在位置

5/S.rfind(T):反向查找,字符串T第一个字符在S中最后出现的位置

#include <string>
#include <iostream>
using namespace std;
int main()
{ string S("1a2b3c4d5e6f7g8h9i1a2b3c4d5e6f7g8h9i");
string T;
string::size_type pos;
cout<<"S="<<S<<endl; pos=S.find("4g");
if(pos!=S.npos)//如果没找到,返回一个特别的标志c++中用npos表示 这里npos取值是4294967295
cout<<"S.find(4g)"<<"position is:"<<pos<<endl;
else
cout<<"Not found the(4g)"<<endl; pos=S.find_first_of("6h");
cout<<"S.find_first_of(6h)is:"<<pos<<endl; pos=S.find("2b",);
cout<<"S.find(2b,5)is:"<<pos<<endl; T="2b";
pos=;
int i=;//查找S中字符串T出现的所有位置。
while((pos=S.find_first_of(T,pos))!=string::npos){
cout<<"position"<<i<<":"<<pos<<endl;
pos++,i++;
} T="acb12389xefgxyz789";
pos=T.find_first_not_of(S);
cout<<"T.find_first_not_of(S):"<<pos<<endl; T="3c4d";
pos=S.rfind(T);
cout<<"S.rfind(3c4d):"<<pos<<endl;
}

最新文章

  1. 最近碰到的一些 SSL 问题记录
  2. redis原子性读写操作之LUA脚本和watch机制
  3. 基于 URL 的权限控制
  4. IOS-错误总结
  5. view的加载
  6. PS-添加前景色
  7. 基于UUID生成短ID
  8. WordPress Duplicator 0.4.4 Cross Site Scripting
  9. Android开发手记(24) Log的使用及颜色的更改
  10. asp.net插入sql server 中文乱码问题解决方案
  11. 学习笔记CB002:词干提取、词性标注、中文切词、文档分类
  12. ARTS打卡计划第二周-Algorithm
  13. 《一头扎进SpringMvc视频教程》
  14. ecna2017-Game of Throwns
  15. 分类-MNIST(手写数字识别)
  16. HDU 5813 Elegant Construction 构造
  17. bind系统调用
  18. 【CF954I】Yet Another String Matching Problem(FFT)
  19. Android AOSP 单独编译某一模块
  20. 解决xshell6评估过期,需采购问题

热门文章

  1. UIStoryboard小提示
  2. DEDECMS自定义表单提交后的跳转链接修改方法
  3. WPF InitializeComponent() 方法介绍
  4. Effective C++ Item 10,11 Have assignment operators return a reference to *this Handle assignment to self in operator =
  5. UE4关于编译配置的参考(Debug,DebugGame,Development,Shipping,Test等)
  6. 01.ActiveMQ安装部署
  7. Spring的事物传播行为
  8. Spring 拦截器的使用
  9. 第十一课——codis-server的高可用,对比codis和redis cluster的优缺点
  10. session------&gt;防表单重复提交