This program is meant to store a list of usernames, add usernames, and delete them as well. My code works as intended except for the first step. Whenever i enter a name to be stored nothing shows up on the list, and because of this nothing can be deleted. Im not sure where i messed up because i went over it and everything looks fine. I also do not get any error messages so i dont have any direction as to what i should be looking for. Any help would be great, thanks.
#include <iostream>
#include <string>
#include <vector>
using std::cout, std::cin, std::string, std::vector;
void printUserList(vector<string> listUser) {
cout << "Current User List
";
for(int x = 0; x < listUser.size(); ++x) {
cout << x << "" << listUser[x] << "
";
}
}
int main() {
vector<string> addUser;
vector<string> userBase;
string userName;
char choice;
bool keepLooping = true;
while(keepLooping) {
cout << "User Options:
"
<< "1. Add a username
"
<< "2. List all username
"
<< "3. Delete a username
"
<< "X. Exit
";
cout << "Enter Option: ";
cin >> choice;
cin.ignore();
switch(choice) {
case '1': {
cout << "Enter username: ";
getline(cin, userName);
cout << "
";
if(userName.size() > 0) {
addUser.push_back(userName);
cout << "User has been added
";
}
} break;
case '2': {
printUserList(userBase);
} break;
case '3': {
int index;
printUserList(userBase);
cout << "Enter the index of the user: ";
cin >> index;
cin.ignore();
if(index < userBase.size()) {
userBase.erase(userBase.begin() + index);
cout << "User deleted";
}
} break;
case 'X': {
userBase.clear();
keepLooping = false;
} break;
default: {
cout << "Option not found, please try again.";
}
}
}
return 0;
}
question from:
https://stackoverflow.com/questions/65894880/undeclared-issue-not-sure-how-to-fix 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…