fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <stdlib.h>
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10. //this vector will store the integers
  11. vector<int> a;
  12. // this will store the user input
  13. string inp;
  14. getline(cin, inp);
  15. // this string will temporarily store the digits
  16. string tmp;
  17. //be sure that the reading part is okay
  18. cout << inp << endl;
  19. //until you meet something different than a digit, read char by char and add to string
  20. for(int i = 0; i <= inp.length(); i++)
  21. {
  22. if(isdigit(inp[i]))
  23. {
  24. tmp +=inp[i];
  25. }
  26. else
  27. {
  28. // when it is not a character, turn to integer, empty string
  29. int value = atoi(tmp.c_str());
  30. a.push_back(value);
  31. tmp = "";
  32. }
  33. }
  34. // paste the entire vector of integers
  35. for(int i = 0; i < a.size(); i++)
  36. {
  37. cout << a[i] << endl;
  38. }
  39. return 0;
  40. }
Success #stdin #stdout 0s 3036KB
stdin
25 30 46
stdout
25 30 46
25
30
46