I've a program that accepts a user's input, checks if the input is empty, and also if it matches up to a vector of strings (as it's a username-style program).
However, how would I go about cancelling the checking of the string to see if it matches one in the vector if the command was say, /help, or /commands? Naturally, if someone enters one of those commands, I'd like it not to check if it's a username, but display the help topics etc.
I was thinking about using a break, but I'd like some help as I am quite inexperienced with C++. Here's the relevant part of my code so far:
vector <string> unamevec(1,"Administrator"); //Declare vector.
bool isValidUserName(const string& input) { //Check username is in vector
for(int i = 0; i < 1; ++i) {
if(input == unamevec[i]) {
return true;
}
}
return false;
}
int main() {
string userinput;
string accesslevel;
while (userinput.empty()){ //Check for empty input
cout << "Please enter your identity.\n"; //Identify user
getline(cin, userinput);
if (!isValidUserName(userinput)) {
do //Check to see if user is the same as the vector "unamevec"
{
cout << "This user is either non existent or has access privileges revoked.\n"; //Wrong username!
cout << "Please re-enter the username.\n";
getline(cin, userinput);
}
while (!isValidUserName(userinput));
}
}