Pointer structures in Borland C++
Syntax
istream& read(char*, int);
istream& read(signed char*, int);
istream& read(unsigned char*, int);
Description
The read member function extracts a given number of characters into an array. Use gcount() for the number of characters actually extracted if an error occurred.
Can not find a match for
fstream::read(STRUCT*,unsigned int)
And there is just no way to convert the STRUCT* to a void* or char*.
Good luck
Starfall
you just say this:
if( file.read((char*)&myStruct,sizeof(STRUCT)) != sizeof(STRUCT) )
// then you had an error
good luck
And the solution was JUST the thing that I haven't thought about. You see: the solution is in the place where you least expected.
I had tried things like:
char *ptr;
MYSTRUCT mstruct;
ptr=&mstruct
That wouldn't work. But type casting does work.
code:, as I've heard it provides a safer way to cast un-related types (in your case your struct type).reinterpret_cast (var_struct)
[This message has been edited by joeG (edited December 19, 1999).]
fstream file;
file.open("test.tst",0x81);
file.read(&struct,sizeof(struct));
file.close();
Many other C++ compilers doesn't seem to have problems with this, only borland's. Any way to solve this?
MYSTRUCT mstruct;
ptr=&mstruct
This should also work, if you want to do it this way - just use:
ptr = (char*)&mstruct
Regards
Starfall