fork download
  1. // string::substr
  2. #include <iostream>
  3. #include <string>
  4.  
  5. int main ()
  6. {
  7. std::string stringToCheck = "xyz";
  8. std::string stringArray[] = { "000", "999", "666xyz", "xyz" };
  9.  
  10. int length = sizeof(stringArray) / sizeof(stringArray[0]);
  11.  
  12. for(std::string i : stringArray)
  13. {
  14. std::cout << i << " \n";
  15.  
  16. if(!(i.find(stringToCheck)<i.length()))
  17. {
  18. std::cout << i << " Not Found " << " \n";
  19. }
  20. else
  21. {
  22. std::cout << i << " Found " << " \n";
  23. }
  24. }
  25.  
  26. std::cout << "\n ----\n\n";
  27. for(int i = 0; i < length; i++)
  28. {
  29. std::cout << stringArray[i] << " " << i << " \n";
  30.  
  31. if(stringArray[i] != stringToCheck)
  32. {
  33. std::cout << stringArray[i] << " Not Found " << i << " \n";
  34. }
  35. else
  36. {
  37. std::cout << stringArray[i] << " Found " << i << " \n";
  38. }
  39. }
  40.  
  41. return 0;
  42. }
  43.  
Success #stdin #stdout 0.01s 5268KB
stdin
Standard input is empty
stdout
000 
000 Not Found  
999 
999 Not Found  
666xyz 
666xyz Found  
xyz 
xyz Found  

 ----

000 0 
000 Not Found 0 
999 1 
999 Not Found 1 
666xyz 2 
666xyz Not Found 2 
xyz 3 
xyz Found 3