fork(40) download
  1. #include <iostream>
  2. #include <string>
  3. #include <locale>
  4.  
  5. std::string trim(const std::string &s)
  6. {
  7. std::string::const_iterator it = s.begin();
  8. while (it != s.end() && isspace(*it))
  9. it++;
  10.  
  11. std::string::const_reverse_iterator rit = s.rbegin();
  12. while (rit.base() != it && isspace(*rit))
  13. rit++;
  14.  
  15. return std::string(it, rit.base());
  16. }
  17.  
  18. int main() {
  19. std::cout<<"'"<<trim(" trim")<<"'"<<std::endl;
  20. return 0;
  21. }
Success #stdin #stdout 0s 3428KB
stdin
Standard input is empty
stdout
'trim'