C++ libconfig读取列表C
我正在尝试阅读这个用C语言编写的libconfig库进行配置的示例,但是没有看到任何读取列表并存储它的示例C++ libconfig读取列表C,c++,c,list,configuration,libconfig,C++,C,List,Configuration,Libconfig,我正在尝试阅读这个用C语言编写的libconfig库进行配置的示例,但是没有看到任何读取列表并存储它的示例 sound = { string_length = 50; sound_folder = "./bin/sound/"; sounds_number = 4; sounds_list = ( "001_piano.wav", "voz4408.wav", "001_bajo.wav", "001_bateriabuen
sound = {
string_length = 50;
sound_folder = "./bin/sound/";
sounds_number = 4;
sounds_list = ( "001_piano.wav", "voz4408.wav", "001_bajo.wav", "001_bateriabuena.wav" );
};
我想知道是否有一种方法可以加载一个类似于sounds_列表的列表。不要像我现在这样创建一个结构:
sounds_list = ( { file_name = "001_piano.wav";},
{ file_name = "voz4408.wav";},
{ file_name = "001_bajo.wav";},
{ file_name = "001_bateriabuena.wav";}
);
您可以使用以下结构:
test_array = ["aaa", "bbb", "ccc"];
libconfig::Config cfg;
cfg.readFile(conf_file.c_str());
const Setting &test_array = cfg.lookup("test_array");
int count = test_array.getLength();
for (int i = 0; i < count; ++i) {
std::cout << test_array[i] << std::endl;
}
当您想要解析上述参数时,可以使用以下代码:
test_array = ["aaa", "bbb", "ccc"];
libconfig::Config cfg;
cfg.readFile(conf_file.c_str());
const Setting &test_array = cfg.lookup("test_array");
int count = test_array.getLength();
for (int i = 0; i < count; ++i) {
std::cout << test_array[i] << std::endl;
}
您也可以参考以了解更多信息请详细说明您的问题刚刚编辑的问题。谢谢这个问题还不清楚。我想读什么声音;喜欢列表而不是结构,不知道怎么做。