Original Post
Hi, after several month, I return to this forum with another question. You were very helpful last time, s I hope for the same this time :p I want to read lines from a file in the form: name=value eg: CNFG_SCREEN_WIDTH=1152 CNFG_SCREEN_HEIGHT=864 To do this I wrote the following functions: The DWORDS in assignValueFromFile are defined in another file like so: #define CNFG_SCREEN_WIDTH 111 #define CNFG_SCREEN_HEIGHT 112 I seem to be doing something wrong here though and I can't figure out what. There are no errors on compile, but the debugger show an access violation whenever I try to use the direct3d device, which is created in a function which uses values extracted from a file in the way described above. Before I implemented this file reading thing the program worked well. Thanks Alex
void GEclass::readDataFile(const char* filename)
{
string line;
string strname;
string strvalue;
DWORD Dname;
float value;
size_t equal;
ifstream file (filename);
if (file.is_open())
{
while(!file.eof())
{
getline(file, line);
equal=line.find_first_of("=");
strname = line;
strname.erase(equal);
strvalue = line;
strvalue.erase(0, (equal+1));
Dname = atoi(strname.c_str());
value = (float)(atof(strvalue.c_str()));
assignValueFromFile(Dname, value);
line.clear();
strvalue.clear();
strname.clear();
}
file.close();
}
else
MessageBox (NULL, L"ERROR - a configurationfile could not be opened.", L"VERSUTIA", MB_OK | MB_ICONEXCLAMATION);
return;
}
void GEclass::assignValueFromFile(DWORD name, float value)
{
switch (name)
{
case CNFG_SCREEN_WIDTH:
screen_width = (int)value;
break;
case CNFG_SCREEN_HEIGHT:
screen_height = (int)value;
break;
}
return;
}