fork download
  1. #include <string>
  2. #include <vector>
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. vector<string> stringList;
  10. stringList.push_back("pass");
  11. stringList.push_back("pass");
  12. stringList.push_back("Test pass pass");
  13. string searchWord = "Test";
  14. int searchWordSize = searchWord.size();
  15. int count = 0;
  16.  
  17. for (vector<string>::iterator iter = stringList.begin(); iter != stringList.end(); ++iter) {
  18. for (size_t pos = 0; pos < (*iter).length(); pos+=searchWordSize) {
  19. pos = (*iter).find(searchWord, pos);
  20. if (pos != string::npos)
  21. ++count;
  22. else
  23. break;
  24. }
  25. }
  26.  
  27. cout << "Count: " << count << endl;
  28.  
  29. return 0;
  30. }
  31.  
Success #stdin #stdout 0s 3432KB
stdin
Standard input is empty
stdout
Count: 1