fork(1) download
  1. #include <iostream>
  2. #include <algorithm>
  3.  
  4. using namespace std;
  5.  
  6. std::string Trimed(const std::string& s)
  7. {
  8. std::string::const_iterator begin = std::find_if(s.begin(),
  9. s.end(),
  10. [](char ch) { return !std::isspace(ch); });
  11.  
  12. std::string::const_iterator end = std::find_if(s.rbegin(),
  13. s.rend(),
  14. [](char ch) { return !std::isspace(ch); }).base();
  15. return std::string(begin, end);
  16. }
  17.  
  18. int main() {
  19. string line;
  20.  
  21. while (getline(cin, line))
  22. {
  23. cout << Trimed(line) << "!" << endl;
  24. }
  25. return 0;
  26. }
  27.  
Success #stdin #stdout 0s 3468KB
stdin
 SpaceAtFront
SpaceAtEnd
 SpaceAtBothEnds 
Space in the midle
 Space everywhere 
stdout
!
SpaceAtFront!
SpaceAtEnd!
SpaceAtBothEnds!
Space in the midle!
Space everywhere!