Expand|Select|Wrap|Line Numbers
- <iostream>
- #include<fstream>
- using namespace std;
- class Student
- {
- public:
- char name[10];
- char address[10];
- char Gender;
- char DOB[10];
- Student()
- {}
- };
- int main()
- {
- cout<<"\nWritting on file \n";
- Student *p=new Student[5];
- for(int i=0;i<5;i++)
- {
- cout<<i+1<<": ";
- cin>>p->name;
- cout<<"\n";
- p++;
- }
- ofstream osfile("Student.txt",ios::binary|ios::app);
- osfile.write((char*)p,sizeof(Student)*5);
- osfile.close();
- cout<<"\nreading\n";
- Student *p2=new Student[5];
- ifstream isfile("Student.txt",ios::binary);
- isfile.read((char*)p2,sizeof(Student)*5);
- isfile.seekg(0);
- isfile.close();
- for(int i=0;i<5;i++)
- {
- cout<<i+1<<": ";
- cout<<p2->name;
- cout<<"\n";
- p2++;
- }
- return 0;
- }