fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4.  
  5. std::vector<std::string> str;
  6.  
  7. void setup(){
  8. std::string s = "scott>=tiger>=mushroom>=fail";
  9. std::string delimiter = ">=";
  10.  
  11. size_t start = 0, pos;
  12. std::string token;
  13. while ((pos = s.find(delimiter, start)) != std::string::npos) {
  14. token = s.substr(start, pos-start);
  15. str.push_back(token);
  16. start = pos + delimiter.size();
  17. }
  18. if (start < s.size())
  19. str.push_back(s.substr(start));
  20.  
  21. for(auto &elem : str)
  22. std::cout << elem << std::endl;
  23. }
  24.  
  25. int main() {
  26. setup();
  27. return 0;
  28. }
Success #stdin #stdout 0.01s 5508KB
stdin
Standard input is empty
stdout
scott
tiger
mushroom
fail