I have a text file that I am converting to binary. Its a 7 digit no. followed by a name and then repeat for however many names is listed.
1234567 First Last
7654321 First Last
Because its a 7 digit int, I am having trouble outputting it to the binary using this method with the int struct. It gives me an awfully large .DAT (binary) file whenever I write to it even with say just 3 names. Is there a better way of outputting it so my binary .dat files look about 200kb and doesn’t end up in the 20mb+ range?
const int MAX = 50;
struct StudentRegistration{
int studentID;
char name[MAX];
};
fstream afile;
ifstream infile;
afile.open (fileName2, ios::out | ios::binary);
infile.open (fileName1);
while (infile >> s.studentID)
{
infile.get(space);
infile.getline(&s.name, MAX);
afile.seekp((s.studentID-1)*sizeof(StudentRegistration), ios::beg);
afile.write(reinterpret_cast <const char *>(&s), sizeof(s));
}
afile.close();
infile.close();
I removed the seekp line and it seems to do what I want to it for now.