fork download
  1. #include <set>
  2. #include <iostream>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. string mystring = "Hello World this is my string";
  10. string temp = "";
  11. set<string> myset;
  12.  
  13. for (unsigned int i = 0; i < mystring.length(); i++)
  14. {
  15. if (mystring.at(i) == ' ')
  16. {
  17. myset.insert(temp);
  18. temp = "";
  19. }
  20. else
  21. {
  22. temp.push_back(mystring.at(i));
  23. }
  24. }
  25. myset.insert(temp);
  26.  
  27. for (set<string>::iterator i = myset.begin(); i != myset.end(); i++)
  28. {
  29. cout << *i << endl;
  30. }
  31. return 0;
  32. }
  33.  
Success #stdin #stdout 0.01s 2860KB
stdin
Standard input is empty
stdout
Hello
World
is
my
string
this