C++ Program Write Object on File

This is a Cpp (C++) program for file handling which stores a object on a file. This file stores the student details from the student class object directly by writing the object onto the file. This is also called serialization.
This is a part of Mumbai University MCA Colleges C++ MCA Sem 3

#include<stdio.h>
#include<conio.h>
#include<math.h>
class Student
{
int roll_no;
char cname[20];
public:
void setrollno()
{
cout<<"Enter the rollno:"<<endl;
cin>>roll_no;
}
void setname()
{
cout<<"\nEnter name:"<<endl;
cin>>cname;
}
int getno()
{
return roll_no;
}
char * getname()
{
return cname;
}
};
void main()
{
clrscr();
ofstream sfil("STUDENT");
Student st;
st.setrollno();
st.setname();
sfil<<st.getno();<<' ';
sfil<<st.getname();
}

Hope this Program is useful to you in some sense or other. Keep on following this blog for more Mumbai University MCA College Programs. Happy Programming and Studying.

No comments:

Post a comment