Hi
I'm still reading Prata's book and there is a section where they explain how to write files using the binary mode.
They define a struct
Code:
const int LIM = 20;
struct planet
{
char name[LIM];
double population;
double g;
};
planet pl;
And they say you can use the binary mode to write the whole struct at once (in text mode you need to specify every member).
Code:
ofstream fout("planets.dat",
ios_base:: out | ios_base::app | ios_base::binary);
fout.write( (char *) &pl, sizeof pl);
I don't understand why they use
Code:
fout.write( (char *) &pl, sizeof pl)
instead of just
Code:
fout.write( pl, sizeof pl)