Advertisement
Guest User

Untitled

a guest
May 19th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. #include <iostream>
  2. #include <sstream>
  3. #include <vector>
  4.  
  5. // Method to parse a string using the `delim` character
  6. std::vector<std::string> parse(std::string input, char delim) {
  7. std::vector<std::string> tokens;
  8.  
  9. std::stringstream stream(input);
  10. std::string token;
  11.  
  12. while(getline(stream, token, delim)) {
  13. tokens.push_back(token);
  14. }
  15.  
  16. std::string lastToken = tokens[tokens.size() - 1];
  17. //tokens[tokens.size() - 1] = lastToken.substr(0, lastToken.length() - 1);
  18.  
  19. return tokens;
  20. }
  21.  
  22. // Convert an integer represented as a string into an int
  23. int stringToInt(std::string str) {
  24. int ans = 0;
  25.  
  26. for (int i = 0; i < str.length(); i++) {
  27. ans = ans * 10 + (str[i] - '0');
  28. }
  29.  
  30. return ans;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement