How to create ptr to ifstream and use structures?[RESOLVED]
Hi,
I wrote a C++ piece of code to read a binary header (for a bitmap). It works well. I can load the image into an array. No problem!
At the bottom of this posting, you see how I created the object 'in' and read some binary data into 'h' which is a structure (abbreviated piece of code).
1. How would I create this object 'in' using new, then read the values into 'h'? Something like this?
ifstream *p = new ifstream("stone1.bmp",ios::binary | ios::in);
How to read data into object???
2. I can read the binary data into the structure, one member at a time. How would I read the data into the structure 'h' in one line?
Thanks,
ChuckB
Code:
typedef struct {
unsigned short type;
unsigned long size;
unsigned short reserved1;
unsigned short reserved2;
unsigned long offset;
} HEADER;
HEADER h;
ifstream in("stone1.bmp",ios::binary | ios::in);
if(!in)exit(EXIT_FAILURE);
in.read((char*)&h.type, sizeof h.type);
cout << "File type: " << h.type << endl;
in.read((char*)&h.size, sizeof h.size);
cout << "File size: " << h.size << endl;