c ++ string.find() 用法

#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;

int main()
{
    string s;
    string s1;
    cin>>s>>s1;
    s.find(s1);//返回s1在s中的位置,没找到返回-1
    s.find_first_of(s1);//返回任意字符s1在s中第一次出现的位置,s1是字符不可以为字符串
    s.find(s1, a);//从s下标为a开始查找字符串s1,返回起始位置,找不到返回-1
    
    
    
    
   string s="abb abb abb";  //查找字符s1在s中出现的所有起始位置
   string s1="a"; //char s1='a';  
   int position=0;  
   int i=0;  
   while((position=s.find_first_of(s1,position))!=string::npos)  
   {  
       cout<

你可能感兴趣的:(字符串处理)