advanced file handling
by Matthew Shapiro · in Technical Issues · 03/05/2002 (11:37 am) · 3 replies
I really don't want to parse information from a file but i really need to store a structure and extract that exact strucutre. the structure is:
struct playerinfo
{
char name[50];
int level;
int equipment[10];
etc....
}
I'm pretty sure there is a way to EXTRACT this exact struct as it looks like thats how i get the model header for MD2 and other various things... anyone know where i can get some nfo on it?
struct playerinfo
{
char name[50];
int level;
int equipment[10];
etc....
}
I'm pretty sure there is a way to EXTRACT this exact struct as it looks like thats how i get the model header for MD2 and other various things... anyone know where i can get some nfo on it?
#2
03/05/2002 (1:34 pm)
Or, if you aren't using any pointers to other objects in your structure, you can consult the MSDN on the _open, _read, _write, and #pragma pack commands, which do what I think you're looking for.
#3
03/05/2002 (3:57 pm)
hmm I may check those out but I finally figured out how to make my own file format for it after thinkin out how the modelheader in an MD2 works the way it does (at least in opengl game programming)
Torque Owner nohbdy
Just create a << and >> operator for the class like so:
istream &operator>>(istream &stream, StructName &blah)
{
stream >> blah.x;
stream >> blah.y;
}
ostream &operator<<(ostream &stream, StructName &blah)
{
stream << blah.x;
stream << blah.y;
}
if it's a class you probably need to declare the operators as friends like so:
friend ostream &operator<<(ostream &, const StructName &);
friend istream &operator<<(istream &, const StructName &);
if it's just a normal struct (with all public variables) you dont really need to bother with the friend stuff