I came across the statement:
outbal.write( (char*) &acc , sizeof( struct status ) );
outbal is an object of ofstream and status is a type.
Therefore:
struct status {
// code
};
status acc;
Talking about the second line I don’t understand the first argument, which is (char*) &acc. What are we doing and how?
(char*)&accif the address of the variableacc, cast to a char pointer so as to be compatible withostream::write(). It is that variable that is being written, to theoutbalstream, for a length ofsizeof(struct status).ostream::writetakes a memory address and a length and will output that memory to the specified stream. In other words, you’re simply outputting the entire memory contents of theaccvariable.Your code is similar to: