I am trying to read from a input file for a bookstore the books information. I have used getline for reading the file, however, some books have two authors and two different formats, and this is where i am stuck. I need my output to have both names listed as authors and both formats correct, my output is fine until I reach the authors point and also my formats arent correct. Below is the txt file and code I have so far. Some declared variables are for the rest of the program.
**C++ Code:**
string str;
string title;
string authors[4];
string publisher;
string ISBN;
string filename;
string Format;
double cost;
int yearpublished;
int copies;
int numOfcopies;
int numOfauthors;
int numFormats;
char userChoice;
int count = 0;
int num = 0;
int input = 0;
ifstream infile;
int i;
cout << "please enter the name of the file you wish to input:" << endl;
getline(cin, filename);
infile.open(filename.c_str());
if (!infile) {
cout << "file not found!!!" << endl;
exit(0);
}
while (!infile.eof()) {
getline(infile, title);
cout << "Title: " << title <<endl;
getline(infile, ISBN);
cout << "ISBN: " << ISBN << endl;
getline(infile, publisher);
cout << "publisher:" << publisher << endl;
string yearpublished;
getline(infile, yearpublished);
cout << "Year published: " << yearpublished << endl;
string cost;
getline(infile, cost);
cout << "Price:" << cost << endl;
string numOfcopies;
getline(infile, numOfcopies);
cout << "Copies in stock:" << numOfcopies << endl;
string numOfauthors;
getline(infile, numOfauthors);
cout << "Number of authors: " << numOfauthors << endl;
getline(infile, authors[4]);
cout << "Book authors:" << authors[4] << endl;
string numFormats;
getline(infile, numFormats);
cout << "Number of formats:" << numFormats << endl;
getline(infile, Format);
cout << "Book format:" << Format << endl;
string NumPages;
getline(infile, NumPages);
cout << "Number of Pages:" << NumPages << endl;