查找某一给定位置后的子串的位置
1 //从字符串s 下标5开始,(包括5!!)查找字符串b ,返回b 在s 中的下标
2 position=s.find(“b”,5);
下面举例
#include<cstring>#include<cstdio>#include<iostream>using namespace std;int main(){//find函数返回类型 size_typestring s("1a2b3c43d5e6f7jkg8h9i1a2b3c4d5e6f7g8ha9i");string flag;string::size_type position;//find 函数 返回3 在s 中的下标位置 position=4; int i=1; while((position=s.find('3',position))!=string::npos) { cout<<"position "<<i<<" : "<<position<<endl; position++; i++; } return 0;}//输出position 1 : 4position 2 : 7position 3 : 25 #include<cstring>#include<cstdio>#include<iostream>using namespace std;int main(){//find函数返回类型 size_typestring s("1a2b3c43d5e6f7jkg8h9i1a2b3c4d5e6f7g8ha9i");string flag;string::size_type position;//find 函数 返回3 在s 中的下标位置 position=5; int i=1; while((position=s.find("3",position))!=-1) { cout<<"position "<<i<<" : "<<position<<endl; position++; i++; } return 0;}//输出position 1 : 7position 2 : 25