fork download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. void doIt(string datainput)
  6. {
  7. cout << "Input: " << datainput << endl;
  8.  
  9. string str3;
  10.  
  11. int myray[10];
  12. int raycount = 0;
  13.  
  14. bool gettingDigits = false;
  15.  
  16. for (int n = 0; n < datainput.size(); ++n)
  17. {
  18. char ch = datainput[n];
  19.  
  20. //if (isdigit(ch))
  21. if ((ch >= '0') && (ch <= '9'))
  22. {
  23. if (!gettingDigits)
  24. {
  25. str3 = "";
  26. gettingDigits = true;
  27. }
  28.  
  29. str3 += ch;
  30. }
  31. else
  32. {
  33. if (gettingDigits)
  34. {
  35. myray[raycount] = stoi(str3);
  36. raycount++;
  37. str3 = "";
  38. gettingDigits = false;
  39. if (raycount == 10) break;
  40. }
  41. }
  42. }
  43.  
  44. if (gettingDigits && (raycount < 10))
  45. {
  46. myray[raycount] = stoi(str3);
  47. raycount++;
  48. }
  49.  
  50. for (int n = 0; n < raycount; ++n)
  51. cout << "myray[" << n << "] = " << myray[n] << endl;
  52. }
  53.  
  54. int main()
  55. {
  56. doIt("12, 13, 15");
  57. cout << endl;
  58.  
  59. doIt("12 13 15");
  60. cout << endl;
  61.  
  62. doIt("12ab13cd15ef");
  63. cout << endl;
  64.  
  65. return 0;
  66. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
Input: 12, 13, 15
myray[0] = 12
myray[1] = 13
myray[2] = 15

Input: 12 13 15
myray[0] = 12
myray[1] = 13
myray[2] = 15

Input: 12ab13cd15ef
myray[0] = 12
myray[1] = 13
myray[2] = 15