C++ Program to Count The Number of Objects a File
x
36
36
1
2
3
4
5
class temp
6
{
7
char name[25];
8
int code;
9
public:
10
temp()
11
{
12
}
13
temp(char *n, int c)
14
{
15
strcpy(name, n);
16
code=c;
17
}
18
};
19
void main()
20
{
21
temp t[4];
22
t[0]=temp("John", 1);
23
t[1]=temp("Deck", 2);
24
t[0]=temp("Rosh", 3);
25
t[0]=temp("Michael", 4);
26
fstream file;
27
file.open("Employee.dat",ios::in | ios::out);
28
int i;
29
for(i=0;i<4;i++)
30
file.write((char *) &t[i] ,sizeof(t[i]));
31
file.seekg(0,ios::end);
32
int end=file.tellg();
33
cout<<"Number of objects stored in Employee.dat is:"<<endl;
34
sizeof(temp);
35
}
36