fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. using namespace std;
  4.  
  5.  
  6. int main() {
  7. string userinput;
  8. string arr[10] = {"Test1", "Test2", "Test3", "Test4", "Test5", "Test6", "Test7", "Test8", "Test9", "Test10"};
  9.  
  10.  
  11. cout << "Please enter your identity.\n"; //Identify user
  12. getline(cin, userinput);
  13. while (!std::count(arr, arr+10, userinput)) //Check to see if user is the same as the string variable "user"
  14. {
  15. cout << "This user is either non existent or has access privileges revoked.\n"; //Wrong username!
  16. cout << "Please re-enter the username.\n";
  17. getline(cin, userinput);
  18. }
  19.  
  20. cout<< "Got " << userinput << endl;
  21. return 0;
  22. }
Success #stdin #stdout 0s 3436KB
stdin
Test1
asdasd
asdasd
asdsd
sd
Test10
stdout
Please enter your identity.
Got Test1