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?
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));