Hi, i'm after reading a block of data from a file which is in binary, and copying the data to a structure. The struture is exactly alligned to match the data within the file. Could anyone advise us on the type of function to use.... Thanks.
Hi, i'm after reading a block of data from a file which is in binary, and copying the data to a structure. The struture is exactly alligned to match the data within the file. Could anyone advise us on the type of function to use.... Thanks.
Be a leader and not a follower.
Since it's C++ and it's a binary file: ifstream::read()
Code:STRUCTURE MyStructure; ifstream ReadFile; ReadFile.open("MyFile.dat", ios::in | ios::binary); if(!ReadFile.fail()) { ReadFile.read((char*)&MyStructure, sizeof(STRUCTURE)); ReadFile.close(); }
MagosX.com
Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.
right that looks great thanks, why the typecasting to a char pointer though?
Be a leader and not a follower.
Since the ifstream class have no idea what datatypes you may have created, the only type it supports to read/write are char. Probably beacuse one char is 1 byte (most of the time at least).Originally posted by subdene
right that looks great thanks, why the typecasting to a char pointer though?
Otherwise you had to overload the read function yourself for every datatype you have made.
MagosX.com
Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.
Magos, i've implemented the code, but all i get in the structure is garbage.... any ideas? Binary file is ok.... can't see what it could be.
Be a leader and not a follower.
Post some code.
"Queen and huntress, chaste and fair,
Now the sun is laid to sleep,
Seated in thy silver chair,
State in wonted manner keep."
all right got it sorted now thanks, i was reading too far into the binary file.
Be a leader and not a follower.