please...i need a help writing a struct to a binary file!!!!
hi guys
i am wondering whether i can write a struct to a binary file or not?!
well , in this segment of my program :
Code:
enum Status {full, busy, empty};
struct block
{
char* WrdsArray[100];
Status state;
int NumberOfWrds;
int NumberOfBlock;
};
int main()
{
fstream myfile;
myfile.open("file1.bin",ios::binary|ios::out);
block b;
for(int i = 0; i<100; i++)
{
b.WrdsArray[i] = " NON ";
}
b.NumberOfBlock = 0;
b.NumberOfWrds = 0;
b.state = empty;
myfile.write(reinterpret_cast<char*>(b),512);
myfile.close();
when i wanna have my program compiled , i get the error :
error C2440: 'reinterpret_cast' : cannot convert from 'block' to 'char *'
and when i try to write in another format , like:
instead of
Code:
myfile.write(reinterpret_cast<char*>(b),512);
i get the compiler error :
error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'block' (or there is no acceptable conversion)
so plzz guys can anyone lead me how to write this struct to my binary file?!!!!