Hello everyone. I am having a problem with my program; it is supposed to read values from an input text file, put the data into a structure, then output the data from the structure into a binary file. The first 2 parts work fine, but I keep ending up with plain text inside my binary file.
Below is the function that is supposed to do the output. staffMem is the structure, size is the number of records in the structure, generated while getting the data from the input text file earlier.
void arrayToBinary (fstream& outfile, char *binName, staffMem s [], int size)
{
outfile.open (binName, ios::out | ios::binary);
if (!outfile)
{
cout << "Binary file \"" << binName
<< "\" failed to open." << endl;
exit (-1);
}
cout << "Binary file \"" << binName
<< "\" successfully opened for writing" << endl;
for (int i = 0; i < size; i++)
{
outfile.write (reinterpret_cast <const char *> (&s[i]), sizeof (s[i]));
}
outfile.close();
cout << "Binary file \"" << binName
<< "\" properly closed and created" << endl;
}
Thanks in advance.