fork download
  1. #include <iostream>
  2. #include <set>
  3. #include <string>
  4. using namespace std;
  5.  
  6. int main() {
  7.  
  8. set<string> names;
  9. string name;
  10. unsigned int nameCounter = 0;
  11.  
  12.  
  13. while (nameCounter < 4) {
  14. cout<<"Enter "<<nameCounter+1<<" name"<<endl;
  15. getline(cin,name);
  16. if (!names.insert(name).second) {
  17. cout << "That was not unique!" << endl;
  18. } else {
  19. nameCounter++;
  20. }
  21. }
  22.  
  23. for (auto listName : names)
  24. {
  25.  
  26. cout << listName << " ";
  27. }
  28.  
  29.  
  30. cout << endl;
  31.  
  32. }
Success #stdin #stdout 0s 3280KB
stdin
Barry
Carl
Carl
Junior
Ben(TheBest)
stdout
Enter 1 name
Enter 2 name
Enter 3 name
That was not unique!
Enter 3 name
Enter 4 name
Barry Ben(TheBest) Carl Junior