3

This is obviously a fairly simple question, as no one else has had this issue such as this with the library.

When I run my program however, boost returns the error "Unrecognised Option Settings.Directoy" However I have defined this in my code and the file I've asked it to read from. Firstly here's my code, short because I did it as a test.

std::string Directory;

try {
    ifstream Config_File("Config.ini");
    options_description Game("Settings");
    Game.add_options()
        ("Directory", value<std::string>(&Directory)->default_value("Example.exe"));

    variables_map vm;
    store(parse_config_file(Config_File, Game), vm);
    notify(vm);

    if (vm.count("Directory"))
    {
        cout << Directory;
    }
}
catch(std::exception& E)
{
    std::cout << E.what() << std::endl;
}

Here is the file it read from "Config.ini"

[Settings]
Directory = "Example.exe"

I have tried debugging this, by changing the file type, name... removing the spaces?

Adding and removing quotation marks to the entry in Directory? Multiple things, which have given me no solution.

ravenspoint
  • 19,093
  • 6
  • 57
  • 103
user1591117
  • 287
  • 2
  • 5
  • 13

1 Answers1

5

Remove the line

[Settings]

from your config file.

Alternatively, tell the configuration file parser that you are using sections, like this:

  Game.add_options()
        ("Settings.Directory", ...

http://www.boost.org/doc/libs/1_55_0/doc/html/program_options/overview.html#idp163379208

ravenspoint
  • 19,093
  • 6
  • 57
  • 103
  • Thanks, this worked perfectly! Thanks for also showing me the resource, and how I can keep the sections in my file also... as I will need this when the file expands in the future. Thanks again! – user1591117 Sep 08 '14 at 19:25