fork download
  1. #include <iostream>
  2. #include <sstream>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. std::string listOfCommands = "add boo, yorkshire terrier, 01-13-2017, 7, boo puppy.jpg";
  9. string functionToApply = listOfCommands.substr(0, listOfCommands.find(" "));
  10. int position = listOfCommands.find(" ");
  11. listOfCommands.erase(0, position + 1);
  12. cout << listOfCommands << std::endl;
  13. if (functionToApply == "exit")
  14. return 0;
  15. else if (functionToApply == "add")
  16. {
  17. position = listOfCommands.find(", ");
  18. string name = listOfCommands.substr(0, position);
  19. listOfCommands.erase(0, position + 1);
  20. position = listOfCommands.find(", ");
  21. string breed = listOfCommands.substr(0, position);
  22. listOfCommands.erase(0, position + 2);
  23. position = listOfCommands.find(", ");
  24. string birthDate = listOfCommands.substr(0, position);
  25. listOfCommands.erase(0, position + 2);
  26. position = listOfCommands.find(", ");
  27. string nrShorts = listOfCommands.substr(0, position);
  28. listOfCommands.erase(0, position + 2);
  29. string photo = listOfCommands;
  30. std::cout << name << ", "
  31. << breed << ", "
  32. << birthDate << ", "
  33. << nrShorts << ", "
  34. << photo << std::endl;
  35.  
  36. }
  37. }
  38.  
Success #stdin #stdout 0s 4176KB
stdin
Standard input is empty
stdout
boo, yorkshire terrier, 01-13-2017, 7, boo puppy.jpg
boo,  yorkshire terrier, 01-13-2017, 7, boo puppy.jpg