我的代码一直在跳过部分说明,我认为它与getline有关。
if (userChoice == 'L') {
userChoice = NULL;
char option;
cout << "What are you searching for?" << endl;
cout << "1. Name" << endl;
cout << "2. Number" << endl;
cout << "3. Address" << endl;
cin >> option;
while (option != '1' && option != '2' && option != '3') {
cout << "That was not a valid input. Please try again: " << endl;
cin >> option;
}
if (option == '1') {
string find;
cout << "Enter the full name you are looking for: " << endl;
getline(cin, find);
bool found = false;
for (int i = 0; i < a; i++) {
if (Ptr[i].getName() == find) {
found = true;
cout << "Entry Found: " << endl;
cout << Ptr[i].getName() << endl << Ptr[i].getAddress() << endl << Ptr[i].getNumber() << endl;
i = a;
}
else if(Ptr[i].getName() != find)
{
i++;
}
}
}
输出打印初始菜单,让用户输入一些内容(1是现在唯一真正的选项)然后要求用户输入他们要查找的名称,但在此之后立即跳过if语句的其余部分,将主菜单输出到程序。