Program 7 – Binary File Implementation

Write a program that creates a binary file by reading the data for the students from the terminal. The data of each student consists of roll no., name ( a string of 30 or lesser no. of characters) and marks.

using namespace std;

class student{
    int rn, marks;
    char name[30];
    void getData()
        cout << "Enter name: ";
        cin >> name;
        cout << "Enter roll no: ";
        cin >> rn;
        cout << "Enter marks: ";
        cin >> marks;

int main()
    int m;
    fstream f;"Student.txt",ios::binary|ios::out);
    cout << "Enter number of students: ";
    cin >> m;
    student st[m];
    for(int i=0;i<m;i++)
        f.write((char *)&st[i], sizeof(st[i]));
    return 0;