上篇说到了如何设计了数据 采用了啥方式
先干了再解释
同步奥特曼属性到程序-源码实现
//从文件加载迪迦奥特曼属性数据到程序中
void LoadUltramanMainAttribute(vector<DejaAltmanAttribute>& dejaAltmanAttribute){
//打开迪迦奥特曼属性.txt文件读取
ifstream stream("迪迦奥特曼属性.txt", ios::in);
//如果成功打开文件流
if (stream.is_open()) {
//循环读取文件中的每个属性集
while (stream) {
DejaAltmanAttribute de;
//读取属性类型 '复合型'
stream >> de.Type;
int num = 0;
//再读取7个attribute pair
while ( stream && num < 7) {
//构造pair
stream >> PairAttribute.first >> PairAttribute.second;
//加入到Attribute容器中
de.Attribute.emplace_back(forward<decltype(PairAttribute)>(PairAttribute));
//统计已读属性数
num++;
}
//读取完毕一个属性集后,加入到容器中
dejaAltmanAttribute.emplace_back(forward<decltype(de)>(de));
}
}
}
一共有 4个这样的奥特曼属性
`复合型
飞行速度 5马赫
走行速度 1.5马赫
水中速度 1.5马赫
地中速度 1.5马赫
跳跃力 800米
握力 5万吨
必杀技 哉佩利敖光线`
while (stream) {文件流 读到的不是文件结束符
num = 0; 把num 直0
DejaAltmanAttribute de;创建DejaAltmanAttribute 结构体变量 de
stream >> de.Type;读取掉复合型
文件流 读到的不是文件结束符 并且没有读到8个
while (stream && num <7) {
pair<string, string> PairAttribute;
读取 飞行速度 5马赫
stream >> PairAttribute.first >> PairAttribute.second;
放入属性池里
de.Attribute.emplace_back(forward<decltype(PairAttribute)>(PairAttribute));
num++;统计提供有多少能读到
}
读取完毕后放入到dejaAltmanAttribute里
dejaAltmanAttribute.emplace_back(forward<decltype(de)>(de));
}