Question: void Inputdb(vector & libDB) //Function to load database { string sat; //temporary container to read rom file ifstream file; //handle to read from input file

void Inputdb(vector& libDB) //Function to load database {
string sat; //temporary container to read rom file ifstream file; //handle to read from input file
file.open("database.txt"); //to check if the file has been opened successfully
if (file.is_open()) {
while (!file.eof()) {
Asset temp_a; //local variable to temporarily store info of the asset getline(file, sat, ';');
if (sat.size() > 0) //to check if we have reached the end of the file
{
temp_a.type = sat; getline(file, sat, ';'); temp_a.title = sat; getline(file, sat, ';');
int i = 0;
while (i < sat.size()) {
Author temp_auth; //local variable to store names of thea authors string fname, lname;
while (sat[i] != ' ') {
fname += sat[i];
i++; }
temp_auth.fname = fname;
i++; //to jump over the while space between fname and lname while (sat[i] != ',' && i < sat.size())
{
lname += sat[i]; i++;
}
temp_auth.lname = lname; temp_a.authors.push_back(temp_auth); i++;
}
getline(file, sat, ';');
temp_a.YOP = sat;
getline(file, sat, ';');
temp_a.ISBN = sat;
getline(file, sat, ';');
temp_a.libID = sat;
getline(file, sat, ';');
temp_a.tot = stoi(sat);
getline(file, sat, ';');
temp_a.avb = stoi(sat);
getline(file, sat); //to get rid of any newlines at the end ofthe text fi libDB.push_back(temp_a);
}
} file.close();
} else
{
cout << "Could not open datain successfully" << endl;
}
}
can you explain the code line by line plz ty

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!