Advertisement
Guest User

14th

a guest
Apr 26th, 2015
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. #include<iostream>
  2. #include<conio.h>
  3. #include<fstream>
  4. using namespace std;
  5. class student
  6. {
  7. int marks,rollno;
  8. char name[30];
  9. public:
  10. void getdata()
  11. {
  12. cout<<"Enter roll no.: ";
  13. cin>>rollno;
  14. cout<<"Enter name: ";
  15. cin.ignore();
  16. gets(name);
  17. cout<<"Enter marks: ";
  18. cin>>marks;
  19. }
  20. void display()
  21. {
  22. cout<<"Roll No.: "<<rollno<<endl;
  23. cout<<"Name : "<<name<<endl;
  24. cout<<"Marks :"<<marks<<endl;
  25. }
  26. };
  27. main()
  28. {
  29. student s1[10],s2[10];
  30. fstream f;
  31. cout<<"Enter no. students :";
  32. int n;
  33. cin>>n;
  34. f.open ("qwerty.txt", ios::binary | ios::in | ios::out|ios::trunc);
  35. if(!f.is_open())
  36. {
  37. cout<<"not found";
  38. }
  39. for(int i=0;i<n;i++)
  40. {
  41. s1[i].getdata();
  42. f.write((char*) &s1[i], sizeof(student));
  43.  
  44. }
  45. f.seekg(0);
  46. char ch;
  47. for(int i=0;i<n;i++)
  48. {
  49. f.read((char*) &s2[i], sizeof(student));
  50. s2[i].display();
  51. }
  52. f.close();
  53.  
  54. getch();
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement