void cSettings::Parser() {
std::ifstream file(fname.c_str());
while(file.is_open() && !file.eof()) {
//read a line from the file
std::string line;
std::getline(file,line);
//creating the regex expression used to draw out the value and key
std::regex regx(":?[A-z0-9#][A-z0-9.]");
std::regex_iterator<std::string::iterator> it (line.begin(), line.end(), regx);
std::regex_iterator<std::string::iterator> iend;
if (it->str()[0] != '#') {
std::string key = it->str();
++it;
//convert second match to float
std::stringstream ss(it->str());
float val = 0;
ss >> val;
values[key] = val;
}
}
file.close();
}
First of all, "while(!file.eof()) " is wrong, use while(getline(file, line)).
Now, step through your program and look at what your regex is matching
At line #1, it's matching "#G", leaving "raphic settigns" as the suffix
the first char of the match is #, so you continue, this is fine
at line #2, it's offered an empty string, so it leaves the match results empty (with it->size() == 0).
You're then accessing the empty match out of bounds with it->str()[0]. I don't know for sure if this is when you got your runtime error - sounds like you have Visual Studio, which I can't reach right now, but it is an error in any case.
Now if you fix that, you come to line #3, where your regex matches "bl", leaving "oom = 3.56" as the suffix.
you're storing "bl" as your key and advancing the iterator, which proceeds to execute the next search, where it matches "oo", leaving "m = 3.56" as the suffix.
"oo" of course cannot be stored in a float, and your val is zero.
If I were you, I'd have used a different regex, with two capture groups, one to capture the key and another to capture the value. No iterators, no hassle.