fork download
  1. #include <vector>
  2. #include <string>
  3. #include <iostream>
  4. #include <cstdio>
  5. #include <cstring>
  6.  
  7. struct User {
  8. std::string name, game;
  9. User(const char* nam, const char* gam) : name(nam), game(gam) {}
  10. const char* getUsername() const {
  11. return name.c_str();
  12. }
  13. };
  14.  
  15. bool verify(char * a, std::vector<User> b) {
  16. for (int i = 0; i < b.size(); i++) {
  17. if (std::strcmp(a, b[i].getUsername()) == 0) {
  18. return false;
  19. }
  20. }
  21. return true;
  22. }
  23.  
  24. int main(){
  25. std::vector<User> users;
  26.  
  27. User us1("foo", "bar");
  28. users.push_back(us1);
  29.  
  30. char username[100];
  31. bool first = true;
  32.  
  33. do {
  34. if (!first) std::cout << username << ": no good!\n";
  35. else first = false;
  36. std::cout << "Enter Username: ";
  37. std::scanf(" %50s", username);
  38. } while(!verify(username, users));
  39.  
  40. return 0;
  41. }
Success #stdin #stdout 0s 3420KB
stdin
foo
foo
foo
Greg
stdout
Enter Username: foo: no good!
Enter Username: foo: no good!
Enter Username: foo: no good!
Enter Username: