question archive Only File handling and classes in library management system project code in c++

Only File handling and classes in library management system project code in c++

Subject:Computer SciencePrice:4.84 Bought3

Only File handling and classes in library management system project code in c++. Can u plz help in the first evaluation of my project by telling be just the classes and file handling code in c++ of library management system. Give me the code of these without any errors.

pur-new-sol

Purchase A New Answer

Custom new solution created by our subject matter experts

GET A QUOTE

Answer Preview

The major three classes in the file handling are:

 

1) ifstream

 

Helps in reading the files

 

2) ofstream

 

Helps in writing the files

 

3) fstream

 

It helps in both reading and writing files.

Step-by-step explanation

Writing files:

 

#include <iostream>

 

// it includes the file stream classes from the library.

#include <fstream>

using namespace std;

 

int main() {

  // Create and open a text file

 ofstream file("filename.txt");

 

  // Write to the file

file << "Files can be tricky, but it is fun enough!";

 

// Closes the file stream

file.close();

}

 

 

Reading files:

 

#include <iostream>

 

// it includes the file stream classes from the library.

#include <fstream>

using namespace std;

 

int main() {

// Create a text string, which is used to output the text file

string str;

 

// Read from the text file

ifstream file("filename.txt");

 

while (getline ( file, str))

{

  // Print the read line to the context

  cout << str;

}

 

// Closes the file stream

file.close();

 

}

Related Questions