fork(2) download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. std::string str="one apple two apples three apples";
  9. std::string search="apple";
  10. for(std::string::size_type pos=0; pos<str.size(); pos+=search.size())
  11. {
  12. pos=str.find(search, pos);
  13. if(pos==std::string::npos)
  14. break;
  15. std::cout<<"Match found at: "<<pos<<std::endl;
  16. }
  17. return 0;
  18. }
Success #stdin #stdout 0.02s 2812KB
stdin
Standard input is empty
stdout
Match found at: 4
Match found at: 14
Match found at: 27