source file name: OOfiles.cpp

#include <iostream.h>

#include<stdio.h>

#include<conio.h>

#include<iomanip.h>

#include <fstream.h>

class Student

{

char name[10];

int  rollno;

char course[10];

public:

void getdata()

{

cout<<"enter name: ";   cin>>name;

cout<<"enter roll no:"; cin>>rollno;

cout<<"enter class:";   cin>>course;

}

void display()

{

cout<< setw(10)<<name;

cout<< setw(10)<<rollno;

cout<< setw(10)<<course;

cout<<endl;

}

};

int main()

{

Student stud[3];




clrscr();

fstream fin;

fin.open("stud.txt",ios::in|ios::out);

for(int i=0;i<3;i++)

{

stud[i].getdata();

fin.write((char*)&stud[i],40);

}

       fin.seekg(0);

cout<<"contents of file\n";

for(int k=0;k<3;k++)

{

fin.read((char*) &stud[k],40);

stud[k].display();


}

fin.close();


getch();

return 0;

}

output: