struct DATAs
{
char data1;
short data2;
short data3;
float data4;
int data5;
short data6;
unsignedshort data7;
short data8;
char data9;
};
void fixFile(char* filename)
{
std::ifstream InputFile;
InputFile.open(filename, std::ios::binary);
DATAs FileDatas;
InputFile.read(reinterpret_cast<char*>(&FileDatas), sizeof(FileDatas));
}
Can someone explain clearly why I need to use "reinterpret_cast" for the reading instead of "InputFile.read(&FileDatas, sizeof(FileDatas))" ?
The structure of the file are known and tested, I just copied the struct from a similar program's source code, there I found this cast method so that is why I am asking.
Thank you ! and can you tell me what exactly the "reinterpret_cast" doing ? I know its converts the structure into char, but it will be converted back when the read process finished ?
No, it's not converting the structure, it's telling the compiler "I know you think this pointer points to DATAs. Ignore that for a moment and assume it really points to a char". The cast produces no code, it only affects how the compiler checks types.