fork download
  1. #include <iostream>
  2. #include <sstream>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7. stringstream ss("this is a quite long name 1 2 3 4");
  8. string name;
  9. string name_item;
  10. int i;
  11. do {
  12. ss >> name_item;
  13. name += name_item + ' ';
  14. ss >> i;
  15. if ( ss.eof() ) {
  16. //required only in case no ints are passed
  17. } else if ( ss.fail() ) { //we tried to extract an int, but there was another string
  18. ss.clear();
  19. } else { //here we extract all the ints
  20. cout << i << ' ';
  21. while (ss >> i) {
  22. cout << i << ' ';
  23. }
  24. }
  25. } while (!ss.eof());
  26. name.erase(name.length()-1);
  27. cout << endl << name << '.' << endl;
  28. }
Success #stdin #stdout 0s 3480KB
stdin
Standard input is empty
stdout
1 2 3 4 
this is a quite long name.