fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <sstream>
  4. #include <algorithm>
  5.  
  6. int main() {
  7.  
  8. std::string line_string;
  9. while ( getline( std::cin, line_string ) ) {
  10.  
  11. // Instead of `split`, read out of a std::istringstream:
  12. std::istringstream line_stream( line_string );
  13. std::string word;
  14. while ( line_stream >> word ) {
  15.  
  16. // Use std::reverse instead of a loop:
  17. std::reverse( word.begin(), word.end() );
  18.  
  19. // Always qualify with std:: instead of using namespace std;
  20. std::cout << word << ' ';
  21. }
  22. std::cout << '\n'; // prefer '\n' to std::endl unless you need a flush
  23. }
  24.  
  25. }
Success #stdin #stdout 0.02s 2820KB
stdin
I love you.
You love me.
We're a happy family.
stdout
I evol .uoy 
uoY evol .em 
er'eW a yppah .ylimaf