Book Management System Using file Handling

 // Write a C++ Program to Maintain Book Records using File Handling.

#include<iostream>
#include<fstream>
#include<string>
using namespace std;

struct Books{

    string bookName;
    string authersName;
    int cost;

};

int main()
{
 
 int noOfbooks;
 cout << "Enters the numbers of books : ";
 cin >> noOfbooks;

 struct Books varB[noOfbooks];

 ofstream out("books.txt");
 
 if(!out){

    cout << "Error in opening a file." << endl;

 }
 else{

    cout << "Enter the name of the book ,Authers name , cost of that book respectively : \n";
    for(int i=0; i<noOfbooks; i++){
      cin >>varB[i].bookName>>varB[i].authersName>>varB[i].cost;
     
out <<"Name Of Book : " << varB[i].bookName<<" Auther of the book :  " <<varB[i].authersName<<" Cost of the book : "<<varB[i].cost<<" "<<endl;
     
    }

    cout << "The records are saved in file go and check.";
 }

return 0;
}

Comments