Code
#include<iostream>#include<fstream>
#include<string>
#include<conio.h>
using namespace std;
class marks
{
private:
int oop;
int cal;
int dis;
int s;
int a;
public:
marks():oop(0),cal(0),dis(0)
{ }
void getdata()
{
cout<<"Enter marks of oop: ";
cin>>oop;
cout<<"Enter marks of cal: ";
cin>>cal;
cout<<"Enter marks of dis: ";
cin>>dis;
}
void display()
{
cout<<"OOP = "<<oop<<endl;
cout<<"Cal = "<<cal<<endl;
cout<<"Dis = "<<dis<<endl;
}
};
int main ()
{
marks m;
int s;
m.getdata();
//opening the file in binary mode
ofstream myfile("Writing_Reading_class.txt",ios::binary);
//writing in the file
myfile.write(reinterpret_cast<char *>(&m),sizeof(m));
//closing the file
myfile.close();
//re-opening the file in binary mode
ifstream my("Writing_Reading.txt",ios::binary);
//Reading from the file
my.read(reinterpret_cast<char *>(&m),sizeof(m));
//display
m.display();
cout << "\n\nPress any key to close.";
getch ();
return 0;
}
No comments :
Post a Comment
Note: Only a member of this blog may post a comment.