Skip to main content

Posts

Showing posts with the label program to demonstrate writing an object to a data file and reading it back

Write a program to demonstrate writing an object to a data file and reading it back.

 Here is a program that demonstrates writing an object to a data file and reading it back: #include <iostream> #include <fstream> using namespace std; class Student {     private:         string name;         int roll;     public:         void setName(string n) {             name = n;         }         void setRoll(int r) {             roll = r;         }         void display() {             cout << "Name: " << name << endl;             cout << "Roll: " << roll << endl;         } }; int main() {     Student s1;     s1.setName("John");     s1.setRoll(101);     // Writing object to data file   ...