Most likely, the key you put in the unordered map contains whitespace (which you don't see when outputting it) and therefore is not found later.
In your regex ^(.+)\\s*=\\s*(.+)
, the first (.+)
will greedily match as many characters as possible, including leading and trailing whitespace. The \\s*
following it will always match an empty string. To prevent this, you can use (\\S+)
for non-whitespace only, or use a non-greedy (.+?)
.
By the way, while (!fs.eof())
is wrong. Use while (std::getline(fs, line)) {...}
instead.