I have created multiple records using filing, but I am not able to read the whole data from a file, what should I change in this code to print all the records? Here: dvdTitle, artistName, and dvdGenre are strings. While yearPurchased is of int type
void addDvd()
{
cout << "Enter DVD Title\n";
cin >> this->dvdTitle;
cout << "Enter Artists Name\n";
cin >> this->artistName;
cout << "Enter Year Purchased\n";
cin >> this->yearPurchased;
cout << "Enter DVD Genre\n";
cin >> this->dvdGenre;
fstream DVDfile;
DVDfile.open("DVD.txt", ios::app);
DVDfile << "DVD Title: " << dvdTitle << endl << "Artist Name: "
<< artistName << endl << "Year Purchased: " << yearPurchased << endl
<< "DVD Genre: " << dvdGenre << endl << endl;
}
void displayDvd()
{
fstream DVDfile;
DVDfile.open("DVD.txt", ios::in);
while (!DVDfile.eof())
{
cout << "DVD Title: " << dvdTitle << endl << "Artist Name: "
<< artistName << endl << "Year Purchased: " << yearPurchased
<< endl << "DVD Genre: " << dvdGenre << endl << endl;
}
}