Creating a simple configuration file and parser in C++

前端 未结 12 738
谎友^
谎友^ 2020-12-07 10:55

I am trying to create a simple configuration file that looks like this

url = http://mysite.com
file = main.exe
true = 0

when the program ru

12条回答
  •  日久生厌
    2020-12-07 11:45

    How about formatting your configuration as JSON, and using a library like jsoncpp?

    e.g.

    {"url": "http://mysite dot com",
    "file": "main.exe",
    "true": 0}
    

    You can then read it into named variables, or even store it all in a std::map, etc. The latter means you can add options without having to change and recompile your configuration parser.

提交回复
热议问题