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?
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?
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.
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
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).]
ptr=&mstruct
This should also work, if you want to do it this way - just use:
ptr = (char*)&mstruct
Regards
Starfall
This topic has been locked by a moderator. New replies are not allowed.
With your permission, GameDev.net uses analytics cookies to understand how people use the platform. You can accept analytics or continue with necessary cookies only. Learn more