|
From: Abhijit S. <mu...@gm...> - 2002-09-16 17:17:54
|
Greets, Christian.
> Hi list,
>
>
> how can I write a struct into a file (e.g WriteFile()) and read it ???
> I don't know the size of the struct during reading, how can I realize
that.
For one, you could include a member at the beginning of the struct that
specifies the structure's size.
struct foo
{
unsigned foo_size;
unsigned bar;
char baz;
float strawberry;
};
and read and write it at the beginning of the structure. Also note that many
compilers pad the structures so that members are aligned on dword
boundaries. So sizeof(foo) in the above case need not be 4 + 4 + 1 + 4. It's
better to use a C++ class and have methods that manage the loading and
saving.
Another, more elegant, method would be to use text files for managing
persistance, in the format of the windows .INI files or using the registry
or whatever and load the entries by name. This isn't suitable for
high-performance applications, obviously.
___________________________________________________________
Abhijit Shylanath
E-mail: mu...@gm... || ibr...@bi...
Web-site: http://mudeth.tripod.com/
|