Let's suppose head1
is an 2D array of float and I want to fill it with values read from the binary file file
.
After opening the file with
ifstream file ("myfile.bin", ios::in|ios::binary);
I tried two different ways:
file.read( reinterpret_cast<char*>(&head1), sizeof(head1) );
file.read( (char*) &head1, sizeof(head1) );
Both solutions work, but what's exactly the difference between them? which is "safer"?
After reading some documentation, for me the role of reinterpret_cast
is still a bit obscure and from "Programming: Principles and Practice Using C++" I also read that is better to use this function only if necessary especially for portability problem.
Thanks