Possible Duplicate:
Use getline and >> when read file C++
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);
}
This is the function that I'm trying to run. It runs fine the first time but the second time around the getline doesn't read the title of the book and skips it. It then ends up reading it later on in the second 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();
}
}