fork download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. int main() {
  5. std::string s = "JACK1940383DAVID30284HAROLD68372TROY4392";
  6. std::string::size_type start = 0, end;
  7.  
  8. while ((end = s.find_first_of("0123456789", start)) != std::string::npos) {
  9. std::string name = s.substr(start, end-start);
  10. start = end;
  11.  
  12. int number;
  13. if ((end = s.find_first_not_of("0123456789", start)) != std::string::npos) {
  14. number = std::stoi(s.substr(start, end-start));
  15. }
  16. else {
  17. number = std::stoi(s.substr(start));
  18. }
  19. start = end;
  20.  
  21. // use name and number as needed...
  22. std::cout << name << '/' << number << std::endl;
  23. }
  24.  
  25. return 0;
  26. }
Success #stdin #stdout 0s 5520KB
stdin
Standard input is empty
stdout
JACK/1940383
DAVID/30284
HAROLD/68372
TROY/4392