我的功能有问题,它应该打印出存储的书籍列表
void PrintBooklist(vector<BookList>&book)
{
for(int i=0; i<book.size(); i++)
{
if (book[i].memNumBor = -1)
cout<<book[i].title<<endl;
}
}
但它会打印出“标题”这个词;几次,但将其留空。我检查最后的大小以确保添加的任何内容都被推回,但我无法读出它。提前致谢!
int main()
{
vector<BookList>book;
vector<MemInfo>member;
string memberfile;
string bookfile;
ofstream fout;
ifstream fin;
cout << "\n\t\t\tWelcome to Library Management Services!"<<endl<<endl;
Read_Member(member, fin, memberfile);
Read_Book(book, fin, bookfile);
SignIn(member, book, fin, fout, memberfile, bookfile);
return 0;
}
void Read_Member(vector<MemInfo> &member, ifstream &Fin, string &memberfile)
{
MemInfo temp;
cout<<"Please enter the name of the file that contains the member information: ";
getline(cin,memberfile);
Fin.open(memberfile.c_str());
if(Fin.fail())
{
cout<<endl<<"File containing the member information does not exist.\n"<<endl;
exit (0);
}
ReadInfoMem(Fin);
while (!Fin.eof())
{
member.push_back(temp);
ReadInfoMem(Fin);
}
Fin.close();
for (int i=0; i<member.size(); i++)
{
cout<<endl<<member[i].lName<<endl;
}
}