Program to create binary file : (c ++)
A program that creates a binary file by reading the data for the students from the terminal. The data of each student consist of roll no., name ( a string of 30 or lesser no. of characters) and marks.
A program that creates a binary file by reading the data for the students from the terminal. The data of each student consist of roll no., name ( a string of 30 or lesser no. of characters) and marks.
#include<iostream.h> /*Header File*/
#include<fstream.h>
/*Header File*/
#define m5 /*User Define Function*/
class student
/*Defining
Class*/
{
int rollno , marks;
char nm[30];
public: /*Visibility Label*/
void getdata() /*Memberfunction With No Return Type*/
{
cout<<"\n Enter roll no. : "; /*Displaying
Result*/
cin>>rollno;
char ch=cin.get();
cout<<"\n Enter name of student
: "; /*Displaying
Result*/
cin.getline(nm,30);
cout<<"\n Enter marks : "; /*Displaying
Result*/
cin>>marks;
}
};
int main()
{
student stu[m];
fstream fio;
fio.open("Student.txt",ios::binary|ios::out);
for(int
count=0;count<m;count++)
{
stu[count].getdata();
fio.write((char
*)&stu[count],sizeof(stu[count]));
}
fio.close();
return 0;
}
1 Comments
This comment has been removed by the author.
ReplyDelete