Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<conio.h>
- #include<fstream>
- using namespace std;
- class student
- {
- int marks,rollno;
- char name[30];
- public:
- void getdata()
- {
- cout<<"Enter roll no.: ";
- cin>>rollno;
- cout<<"Enter name: ";
- cin.ignore();
- gets(name);
- cout<<"Enter marks: ";
- cin>>marks;
- }
- void display()
- {
- cout<<"Roll No.: "<<rollno<<endl;
- cout<<"Name : "<<name<<endl;
- cout<<"Marks :"<<marks<<endl;
- }
- };
- main()
- {
- student s1[10],s2[10];
- fstream f;
- cout<<"Enter no. students :";
- int n;
- cin>>n;
- f.open ("qwerty.txt", ios::binary | ios::in | ios::out|ios::trunc);
- if(!f.is_open())
- {
- cout<<"not found";
- }
- for(int i=0;i<n;i++)
- {
- s1[i].getdata();
- f.write((char*) &s1[i], sizeof(student));
- }
- f.seekg(0);
- char ch;
- for(int i=0;i<n;i++)
- {
- f.read((char*) &s2[i], sizeof(student));
- s2[i].display();
- }
- f.close();
- getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement