fork download
  1. #include <iostream>
  2. #include <sstream>
  3. #include <vector>
  4. #include <string>
  5.  
  6. using namespace std;
  7.  
  8. int main() {
  9.  
  10. // Your literal input file formatting goes here
  11. istringstream input(R"inp(
  12. 23 43 12 67
  13. 18 15 22
  14. 12 xxx 23 12 xx 34556 11 11 www
  15. )inp");
  16.  
  17. int current;
  18. vector<int> allIntInputs;
  19.  
  20. while (input >> current || !input.eof()) {
  21. if(input.fail()) {
  22. input.clear();
  23. string crap;
  24. input >> crap; // read anything up to the next
  25. // whitespace delimiter (the default deleimiters)
  26. continue; // with the next item
  27. }
  28. // Everything's fine we'll add another number
  29. allIntInputs.push_back(current);
  30. }
  31.  
  32. // Print all integer values extracted
  33. cout << "Integer values read from input:" << endl;
  34. for(vector<int>::iterator it = allIntInputs.begin();
  35. it != allIntInputs.end();
  36. ++it) {
  37. if(it != allIntInputs.begin()) {
  38. cout << ' ';
  39. }
  40. cout << *it;
  41. }
  42. cout << endl;
  43.  
  44. return 0;
  45. }
Success #stdin #stdout 0s 3476KB
stdin
Standard input is empty
stdout
Integer values read from input:
23 43 12 67 18 15 22 12 23 12 34556 11 11