I'm currently working on fstreams, strings to read config file for my engine, what bugz me is - do I code right.
Example:
fstream f;
string buf;
f.open("config.ini", ios::in);
while(!f.eof())
{
f.getline(&buf, INT_MAX, '\n');
//process
}
As far as I know string class is simple char*, but masked under some sort of interface. If I need to read INT_MAX chars to string there might be buffer overrun...
As far as I've seen there are some methods and variables connected with string active buffer lenght/override/alloc, but maybe fstream take care of them...
BTW, I am also wondering why most of game engines stick with config file structure as follows:
%comment
parameter0=value;
paramerer1=value, value;
They don't seem to be easiest to read, parse... Am I wrong?
So far I can imagine:
f.getline(&str, INT_MAX, '=');
if(str==parameter0)
{
f.getline(&str, INT_MAX, '\n');
//process
}
else if(str==parameter1)
{
f.getline(&str, INT_MAX, '\n');
//process
}
as the best approach, is there a better one? What about comments, do I read first char then rewind???