fork download
  1. #include <set>
  2. #include <iostream>
  3. #include <string>
  4. #include <iomanip>
  5.  
  6. int main()
  7. {
  8. std::set<std::string> myset;
  9. std::string current;
  10. current.reserve(100);
  11. char next;
  12.  
  13. std::cin >> std::noskipws;
  14. while(std::cin >> next) {
  15. if(isspace(next)) {
  16. myset.insert(std::move(current));
  17. current = std::string();
  18. current.reserve(100);
  19. } else
  20. current += next;
  21. }
  22. myset.insert(current); //insert the last word
  23. myset.erase(""); //remove any "blank" words
  24.  
  25. for(auto it=myset.begin(); it!=myset.end(); ++it)
  26. std::cout << *it << '\n';
  27. return 0;
  28. }
Success #stdin #stdout 0s 3024KB
stdin
HELLO world this is my
string.
TEST!
stdout
HELLO
TEST!
is
my
string.
this
world