fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. using namespace std;
  5.  
  6. int main() {
  7. auto fn_Tokenize = [](const std::string& vrx_String, const char vc_Delimeter) -> std::vector<std::string>
  8. {
  9. std::vector<std::string> x_Result;
  10. size_t x_StartOfCurrentSubstring = 0;
  11. size_t x_CurrentDelimeterPos = 0;
  12.  
  13. // First find not delimeter character after last found delimeter position
  14. if(!vrx_String.empty())
  15. {
  16. for(;;)
  17. {
  18. // Find delimiter
  19. x_CurrentDelimeterPos = vrx_String.find_first_of(vc_Delimeter, x_CurrentDelimeterPos);
  20.  
  21. if (x_CurrentDelimeterPos != std::string::npos)
  22. {
  23. // If delimiter was found
  24. x_Result.push_back(vrx_String.substr(x_StartOfCurrentSubstring, x_CurrentDelimeterPos - x_StartOfCurrentSubstring));
  25. ++x_CurrentDelimeterPos;
  26. x_StartOfCurrentSubstring = x_CurrentDelimeterPos;
  27. }
  28. else
  29. {
  30. // If delimiter was not found, loop reached end of string
  31. x_Result.push_back(vrx_String.substr(x_StartOfCurrentSubstring));
  32. break;
  33. }
  34. }
  35. }
  36.  
  37. return x_Result;
  38. };
  39.  
  40. std::vector<std::string> result = fn_Tokenize("", ';');
  41.  
  42. for (std::string a : result)
  43. {
  44. std::cout << a << std::endl;
  45. }
  46.  
  47. std::cout << result.size() << std::endl;
  48.  
  49. // your code goes here
  50. return 0;
  51. }
Success #stdin #stdout 0.01s 5276KB
stdin
Standard input is empty
stdout
0