fork download
  1. #include <iostream>
  2. #include <sstream>
  3. #include <iterator>
  4. #include <vector>
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10. string sentence = "house tree car";
  11.  
  12. cout << "original string: " << sentence;
  13.  
  14. istringstream iss(sentence);
  15. vector<string> tokens;
  16. copy(istream_iterator<string>(iss),
  17. istream_iterator<string>(),
  18. back_inserter< vector<string> >(tokens));
  19.  
  20. cout << "\n new string: ";
  21. for (int i = tokens.size() - 1; i >= 0; i--)
  22. {
  23. cout << tokens[i] << ' ';
  24. }
  25.  
  26. return 0;
  27. }
Success #stdin #stdout 0s 3432KB
stdin
Standard input is empty
stdout
original string: house tree car
     new string: car tree house