If I need to read int from ifstream
int myInt = 0;
fileStream.read(reinterpret_cast<char*>(&myInt), sizeof(int));
is using reinterpret_cast<char*>
correct way to accomplish that?
is using reinterpret_cast correct way to accomplish that?
Yes. Prefer c++ style casts, instead of c style casts.
As suggested in comments, a better way to use the read method function is :
int myInt = 0;
fileStream.read(reinterpret_cast<char*>(&myInt), sizeof(myInt));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With