fork download
  1. #include <iostream>
  2. #include <sstream>
  3. #include <iterator>
  4. #include <algorithm>
  5. #include <string>
  6. #include <vector>
  7.  
  8.  
  9. int main() {
  10. std::string const str = "If ranges are to be a feature of the language "
  11. "then they should probably be supported at language level "
  12. "rather than by some trick";
  13.  
  14. std::istringstream iss(str);
  15. std::vector<std::string> words(
  16. (std::istream_iterator<std::string>(iss))
  17. , std::istream_iterator<std::string>());
  18. auto minmax = std::minmax_element(
  19. words.begin()
  20. , words.end()
  21. , [] (std::string const& lhs, std::string const& rhs) {
  22. return lhs.length() < rhs.length();
  23. });
  24.  
  25. std::cout << "Word with minimum length (" << minmax.first->length()
  26. << "): " << *minmax.first << std::endl;
  27. std::cout << "Word with maximum length (" << minmax.second->length()
  28. << "): " << *minmax.second << std::endl;
  29. }
Success #stdin #stdout 0s 3068KB
stdin
Standard input is empty
stdout
Word with minimum length (1): a
Word with maximum length (9): supported