C++ Program to Count The Number of Objects a File
#include<iostream.h>
#include<conio.h>
#include<fstream>
#include<string.h>
class temp
{
char name[25];
int code;
public:
temp()
{
}
temp(char *n, int c)
{
strcpy(name, n);
code=c;
}
};
void main()
{
temp t[4];
t[0]=temp("John", 1);
t[1]=temp("Deck", 2);
t[0]=temp("Rosh", 3);
t[0]=temp("Michael", 4);
fstream file;
file.open("Employee.dat",ios::in | ios::out);
int i;
for(i=0;i<4;i++)
file.write((char *) &t[i] ,sizeof(t[i]));
file.seekg(0,ios::end);
int end=file.tellg();
cout<<"Number of objects stored in Employee.dat is:"<<endl;
sizeof(temp);
}