Allegro 5循环使用相同名称的配置文件值
Allegro 5 loop through config file values with the same name
我有一个配置文件,用于存储地图
name=map1
width=5
height=5
[tiles]
l=0,0,1,0,0
l=0,1,1,1,0
l=0,1,0,1,0
l=0,1,0,1,0
l=0,0,0,0,0
[/tiles]
我如何循环遍历[tiles]部分,将他的line(l)值存储到我的向量中?
注意:我放置allegro5标记是因为它具有加载配置文件的功能
正如您所发现的,Allegro只会接受许多条目中的最后一个使用相同的密钥。虽然你可以给每一行一个不同的键,但你可以相反,利用=
分配是可选的这一事实:
[tiles]
0,0,1,0,0
0,1,1,1,0
0,1,0,1,0
0,1,0,1,0
0,0,0,0,0
[/tiles]
现在,每行的数据都存储在"key"本身中,"value"为已忽略。
int main() {
ALLEGRO_CONFIG *cfg;
ALLEGRO_CONFIG_ENTRY *entry;
const char* row;
al_init();
cfg = al_load_config_file("config.cfg");
row = al_get_first_config_entry(cfg, "tiles", &entry);
while (entry) {
printf("%sn", row);
row = al_get_next_config_entry(&entry);
}
return 0;
}
经过一段时间的阅读allegro5参考资料,我找到了一个可以做到这一点的方法,并尝试了一次又一次,所以我自己的问题有了答案:
首先,[tile]部分的入口可能有不同的名称,比如:
[tiles]
a=0,0,1,0,0
b=0,1,1,1,0
c=0,1,0,1,0
d=0,1,0,1,0
e=0,0,0,0,0
[/tiles]
那么代码是:
ALLEGRO_CONFIG*config_file=al_load_config_file("example.map");
vector<const char*>lines
ALLEGRO_CONFIG_ENTRY** entry_iterator;
const char* entry;
entry=al_get_first_config_entry(config_file, "tiles", entry_iterator);
while((entry=al_get_next_config_entry(entry_iterator))!=NULL){
lines.push_back(al_get_config_value(config_file, "tiles", entry));
};
相关文章:
- 无法找到/读取配置文件.conf-FileIOException
- 在WSL:configure_file上对config_file的每次调用都失败:配置文件时出现问题
- 一种在C++中读取TXT配置文件的简单方法
- FFMPEG配置文件级别id大小无效
- 配置文件解析器仅返回以前的值
- 我的程序有一个保存配置文件的GUI,如何双击此配置文件以直接加载带有配置数据的GUI?
- Boost program_options将多个配置文件解析结果存储到一个parsed_options中
- Windows 后台服务(系统配置文件)无法使用 C++ 访问 win 10 上的用户 appData 文件夹?
- 我应该如何获取配置文件的绝对路径与 Windows .exe一起发布?
- JPG-如何从ICC配置文件部分APP2读取/提取数据
- 检测到 Conan 配置文件设置与 CMake 之间的编译器版本不匹配
- boost::p rogram_options 配置文件格式
- 如何在Boost::program_options配置文件中为非字符串的自定义选项值类型处理空格
- 如何在 Boost Program_Options 中使用命令行和分层配置文件的选项
- 如何将不可编译的配置文件添加到QT工程中?
- OpenGL不能在核心配置文件中使用glVertexAttrib进行绘制
- 错误 VSP1011:无法获取调试信息.与 /配置文件链接器开关链接
- 解析程序配置文件
- 提升program_option配置文件的不区分大小写的解析
- Allegro 5循环使用相同名称的配置文件值