fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <string>
  5. #include <sstream>
  6.  
  7. int main()
  8. {
  9. std::vector<std::string> vec;
  10. std::string str = "hi my name is aviv and";
  11. std::string word;
  12. std::stringstream sstr(str);
  13.  
  14. while(std::getline(sstr, word,' '))
  15. vec.emplace_back(word);
  16.  
  17. int shift;
  18. std::cout << "Enter the Shift: "; std::cin >> shift;
  19.  
  20. std::rotate(vec.begin(), vec.begin() + shift, vec.end());
  21. for(const auto& it: vec)
  22. std::cout << it << " ";
  23. return 0;
  24. }
  25.  
Success #stdin #stdout 0s 4524KB
stdin
2
stdout
Enter the Shift: name is aviv and hi my