gha890826

5/6課輔-字串連續搜尋

May 13th, 2020 (edited)
939
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.34 KB | None | 0 0
  1. //字串連續搜尋
  2. #include <iostream>
  3. #include <iostream>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     string s1="this is s1, and next is s2. we are strings.",s2="is";
  9.     int target=s1.find(s2,0);
  10.     int counter=0;
  11.     while(target!=string::npos)
  12.     {
  13.         counter++;
  14.         cout<<"found at "<<target<<endl;
  15.         target=s1.find(s2,target+1);
  16.     }
  17.     return 0;
  18. }
Add Comment
Please, Sign In to add comment