我处于项目的第二阶段,我需要将程序扩展为菜单驱动的应用程序,以查询我在 .txt 文件中拥有的数据库。所以,我的麻烦是我不能让我的循环是永久的。它总是在从一个选项初始化到下一个选项时终止。这是我的 int main 代码片段:
int main ()
{
char Q,q;
char S,s;
char task;
string pathname;
string z;
int count=0;
cout << "Welcome to Jason Rodriguez's Library Database." << endl;
cout << "Please enter the name of the backup file: ";
cin >> pathname;
ifstream inFile(pathname.c_str());
while(!inFile.eof())
{
getline(inFile,z);
count++;
}
while (task != 'Q' || task != 'q') {
cout << count << " records loaded successfully." << endl;
cout << "Enter Q to (Q)uit, Search (A)uthor, Search (T)itle, (S)how All: ";
cin >> task;
if ((task == 'Q')||(task =='q'))
{
cout << "Program will now terminate";
break;
}
else if ((task == 'S')||(task =='s'))
{
showAll (loadData (pathname));
cout << endl;
cout << "Enter Q to (Q)uit, Search (A)uthor, Search (T)itle, (S)how All: ";
cin >> task;
}
}
}
我需要在这两个之上的循环中再添加两个选项,但我认为我应该首先让前两个正常工作。之后其他两个应该是即插即用。基本上我想做的是说如果用户输入 Q 或 q,则终止程序。否则,如果用户点击 S 或 s,则激活 showall 功能,然后返回原始查询。但它不起作用。欢迎并感谢您提供帮助。