0

I need to load these values from INI file and print them in the application using C++ Boost Library. The sections have duplicate names. I have been restricted to using C++ Boost Library only. Is there any way that I can edit the section names using code and solve this duplicate name problem? Or any other way to solve this duplicate name problem?

My INI File is as follows:

[parameters]
numColors = 4
boardSize = 11
numSnails = 2
[initialization]
id = 0
row = 3
col = 4
orientation = 0
[initialization]
id = 1
row = 5
col = 0
orientation = 1
[color]
id = 0
nextColor = 1
deltaOrientation = +2
[color]
id = 1   
nextColor = 2
deltaOrientation = +1
[color]
id = 2
nextColor = 3
deltaOrientation = -2
[color]
id = 3
nextColor = 0
deltaOrientation = -1
Anonymous
  • 43
  • 2
  • Where is the problem? There are several instances of each section, but each has its own `id`. For instance, you have `initialization`s 0 and 1, and `color`s 0, 1, 2, and 3 (what seems to be correct according to `[parameters].numColors`... – rturrado Apr 06 '21 at 22:38
  • @rturrado Actually I am new to INI Files. I can not figure out the exact code to read this type of file. I have tried the following code, But it generates error because of duplicate name. I would really appreciate if you could guide me on how to use the id with the section name. `for (auto& section : pt)` `{ std::cout << '[' << section.first << "]\n";` `for (auto& key : section.second)` `std::cout << key.first << "=" << key.second.get_value() << "\n"; }` – Anonymous Apr 07 '21 at 13:03
  • Have a look at this other SO question. It may help: https://stackoverflow.com/q/6175502/260313 – rturrado Apr 07 '21 at 20:54
  • I think it may not be possible with Boost. I have tried one of the solutions in the last link that I passed you, just to get the same duplicate error you are seeing, then investigated a bit further and found this other SO question (have a look at the first comment saying you cannot use Boost to parse INI files with duplicate sections): https://stackoverflow.com/q/15178354/260313 – rturrado Apr 07 '21 at 23:51
  • Okay. Thankyou so much – Anonymous Apr 08 '21 at 14:16
  • 1
    @rturrado If you're interested, I wrote an answer at the duplicate question. – sehe Apr 08 '21 at 21:41
  • @sehe Thanks for letting me know! – rturrado Apr 08 '21 at 21:51

0 Answers0