Manofsteel:
a) This is C++, not C. Therefore, use the standard ifstream file i/o methods.
b) There is a fundamental difference between your structure and the one posted by spitball. Yours contains no dynamically allocated data, while spitball's does. The problems this causes is that while your structure contains a block of 80 characters in its array, meaning write() and read() will read and write the contents of the array, spitball's contains a 4-byte pointer which is 100% useless the next time the program runs. Besides which, assuming the file is entered in notepad or something similar, the string will NOT be exactly 80 characters, meaning your read() will probably read beyond the header and fill in the structure with false values.
Spitball:
You probably want to change your char*'s in the header structure into char arrays, for the reasons mentioned above; although, of course, that still probably won't work properly (I mean using one read() call to fill in the whole structure) - also for the reasons mentioned above. Then, assuming the file is separated by newlines (each section - tileset, name, etc. is on a different line), you can use this:
Code:
#include <fstream>
struct MAPFILEHEADER
{
double engversion;
char tileset[200];
char name[200];
char leftexit[200];
char rightexit[200];
char downexit[200];
char upexit[200];
int width;
int height;
}; //Notice the semicolon here. You need one after every structure/class declaration
std::ifstream file("something.txt");
file >> header.engversion;
file.ignore(1); //Extract the trailing newline character still in the file
file.getline(header.tileset, 200);
file.getline(header.name, 200);
file.getline(header.leftexit, 200);
//etc.
file >> header.width;
file >> header.height;
Ok, so that loads the MAPFILEHEADER structure. But you'll notice that the arrays are 200 in length. That means we're assuming that the input will never be more than 200 characters long, and if it's longer then we're screwed. A better way is to use std::strings and std::getline:
Code:
#include <fstream>
#include <string>
struct MAPFILEHEADER
{
double engversion;
std::string tileset;
std::string name;
std::string leftexit;
//...
int width;
int height;
};
std::ifstream file("something.txt");
file >> header.engversion;
file.ignore(1);
std::getline(file, header.tileset);
std::getline(file, header.name);
std::getline(file, header.leftexit);
//etc.
file >> header.width;
file >> header.height;
This way, no matter how long each member is, it will all get loaded. You can also then check the string and compare it with the == operator (unlike having to use strcmp()), and if you need to you can convert it to a char* using "theString.c_str()".
On the other hand, since I'm not sure how the file looks, I can't say how you'd go about loading the 2D array of tiles. Maybe if you could post a sample of the file?
Hope this helps!