boost :: program_options - 如何处理INI文件中具有相同名称的多个节 [英] boost::program_options - how to handle multiple sections with the same name in INI file
问题描述
在下面的配置中;是有办法处理个别部分。
我正在寻找一种可靠的方式来验证下面的服务器部分。
[basic]
number_of_servers = 3
[server]
ip = 10.20.30.40
password = sdfslkhf
[server]
ip = 10.20.30.41
password = sdfslkhf
[server]
ip = 10.20 .30.42
password = sdfslkhf
[server]
password = sdfslkhf
[server]
ip = 10.20.30.42 $ b $当使用 boost :: program_options 时, code>来解析INI文件,选项名称必须以它们的封闭节名称为前缀。
换句话说,节是选项标识符的一部分,但我不认为您有办法识别哪个节给出 server.ip
变量属于(因此,它是关联的 server.password
)。
我认为你应该考虑 Boost.PropertyTree (也支持INI文件解析)。
In a config like below; is there a way to handle individual sections.
I am looking for a way to validate individual "server" sections below, in a reliable manner.
[basic]
number_of_servers=3
[server]
ip=10.20.30.40
password=sdfslkhf
[server]
ip=10.20.30.41
password=sdfslkhf
[server]
ip=10.20.30.42
password=sdfslkhf
[server]
password=sdfslkhf
[server]
ip=10.20.30.42
解决方案 When using boost::program_options
to parse a INI file, the option names must be prefixed by their enclosing section names.
In other words, sections are part of the option 'identifier', but I don't think you have a way to identify to which section a given server.ip
variable belongs (and thus, which is the associated server.password
).
I think you should consider Boost.PropertyTree (which also supports INI file parsing) for this task.
这篇关于boost :: program_options - 如何处理INI文件中具有相同名称的多个节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!