fork download
  1. /******************************************************************************
  2.  
  3. Welcome to GDB Online.
  4.   GDB online is an online compiler and debugger tool for C, C++, Python, PHP, Ruby,
  5.   C#, OCaml, VB, Perl, Swift, Prolog, Javascript, Pascal, COBOL, HTML, CSS, JS
  6.   Code, Compile, Run and Debug online from anywhere in world.
  7.  
  8. *******************************************************************************/
  9. #include <bits/stdc++.h>
  10. #include <vector>
  11.  
  12. // A quick way to split strings separated via any character
  13. // delimiter.
  14. void adv_tokenizer(std::string s)
  15. {
  16. std::vector<std::string> indexes;
  17.  
  18. // split string by /
  19. std::stringstream ss(s);
  20. std::string index;
  21. while (!ss.eof()) {
  22. getline(ss, index, '/');
  23. indexes.push_back(index);
  24. }
  25.  
  26. //if (index.size() > 0) std::cout << stoi(index) << std::endl;
  27.  
  28. std::cout << "length: " << indexes.size() << std::endl;
  29.  
  30. std::cout << stoi(indexes[0]) << std::endl;
  31. std::cout << stoi(indexes[2]) << std::endl;
  32. }
  33.  
  34. int main(int argc, char const* argv[])
  35. {
  36. std::string b = "2//3";
  37. adv_tokenizer(b);
  38. }
  39.  
Success #stdin #stdout 0s 5288KB
stdin
45
stdout
length: 3
2
3