struct collection
{
string title, author, isbn;
float price;
bool availability;
int borrow;
};
void read1(member a[]);
void read2(collection b[]);
int main()
{
member a[20];
collection b[100];
read1(a);
read2(b);
}
这是我正在尝试运行的功能。它第一次运行良好,但第二次围绕 getline 没有阅读书名并跳过它。然后它稍后会在第二个 getline 中读取它。
void read2(collection b[])
{
ifstream database;
string n1;
cout << "Enter second input file name: ";
getline(cin, n1);
database.open(n1.c_str());
if(database.fail())
{
"Bad file. \n" ;
}
else
{
for(int j=0;!database.eof();j++)
{
getline(database, b[j].title);
cout << b[j].title<<endl;
getline(database,b[j].author);
cout<<b[j].author<<endl;
database>>b[j].isbn;
cout<<b[j].isbn<<endl;
database>>b[j].price;
cout<<b[j].price<<endl;
database>>b[j].availability;
cout<<b[j].availability<<endl;
database>>b[j].borrow;
cout<<b[j].borrow;
}
database.close();
}
}