演示样例中有具体凝视,直接上代码:

#include <iostream>
#include <string>
using std::cout;
using std::endl;
using std::string;
int main(void){
string str1="hi,test,hello";
string str2="test";
//搜索子串。返回子串第一个字符的索引
cout << str1.find(str2)<<endl;
//假设不存在,返回内置常量string::npos,在一些编译器中通常为4294967295
cout << str1.find('k')<<endl;
//从指定索引開始搜索
cout <<str1.find('h',2)<<endl;
//从指定索引搜索指定字符串的前n个字符
cout <<str1.find("her",1,2)<<endl; //在指定字符集合中搜索字符,返回其索引
cout <<str1.find_first_of("AaEeIiOoUu")<<endl;
//从指定索引处開始在指定字符集合中搜索字符
cout <<str1.find_first_of("AaEeIiOoUu",2)<<endl;
//从指定索引处開始在指定字符集合中搜索指定长度字符
cout <<str1.find_first_of("AaEeIiOoUu",2,2)<<endl; //在指定字符集合中逆向搜索字符,返回字符最后索引,相同也具有上面另外两个重载方法
cout <<str1.find_last_of("AaEeIiOoUu")<<endl; //查找字符串中第一个不在字符集合中的字符
cout <<str1.find_first_not_of("AaEeIiOoUu")<<endl;
//查找字符串中最后一个不在字符集合中的字符
cout <<str1.find_last_not_of("AaEeIiOoUu")<<endl; //逆向搜索,也具有和find()一样的重载方法
cout <<str1.rfind('l')<<endl; //截取子串
string str3=str1.substr(3,4);
cout <<str3<<endl;
return 0; }

最新文章

  1. BZOJ4698: Sdoi2008 Sandy的卡片
  2. Android:StatFs类 获取系统/sdcard存储空间信息
  3. What is a First Chance Exception?
  4. Spark1.0 安装
  5. C++之单元测试
  6. Oracle 中的Top写法
  7. ABI &amp; API
  8. Go 程序的性能优化及 pprof 的使用
  9. TCP的ACK确认系列 — 快速确认
  10. wince6.0 编译报错:&quot;error C2220: warning treated as error - no &#39;object&#39; file generated&quot;的解决办法
  11. ruby:借助第三方类名如何查找第三方gem名称(zlib为例)
  12. 树莓派安装 MySQL 时出现错误的解决方法
  13. WIN下的Django安装
  14. windos64位下python3.6安装pywin32的问题
  15. 微信小程序flex佈局
  16. vue.js 键盘enter事件的使用
  17. SpringMVC,Controller的返回页面类型以及路径设置默认值
  18. Java 编程下字符串的 16 位、32位 MD5 加密
  19. 【TCP/IP详解 卷一:协议】TCP定时器 小结
  20. [Git] git merge之squash

热门文章

  1. Traveling
  2. Python 模块的一般处理
  3. linux的nohup命令的用法。
  4. Android4: Write Storage权限问题
  5. (14)[Xamarin.Android] 异步的网络图片下载
  6. i美股投资研报--Michael Kors(IPO版) _Michael Kors(KORS) _i美股
  7. 安装python模块
  8. SP2-0618: Cannot find the Session Identifier. Check PLUSTRACE role is enabled
  9. DLL导出函数和类 之 __declspec(dllexport)
  10. EF(ServerFirst)执行存储过程实例1(带输出参数)